Created
January 7, 2026 22:09
-
-
Save g-maclean/2deb0306c121fecd5da6eea55426b341 to your computer and use it in GitHub Desktop.
Property Hive - redirect off market property URLs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action( 'template_redirect', 'ph_redirect_off_market_properties' ); | |
| function ph_redirect_off_market_properties() { | |
| // Only run on single property posts | |
| if ( ! is_singular( 'property' ) ) { | |
| return; | |
| } | |
| // Allow admins to view off-market properties | |
| if ( current_user_can( 'administrator' ) ) { | |
| return; | |
| } | |
| $property_id = get_queried_object_id(); | |
| if ( ! $property_id ) { | |
| return; | |
| } | |
| $on_market = get_post_meta( $property_id, '_on_market', true ); | |
| // Redirect if not on market | |
| if ( $on_market !== 'yes' ) { | |
| $redirect_url = get_permalink( 123 ); // replace with your page ID | |
| wp_safe_redirect( $redirect_url, 301 ); | |
| exit; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment