Skip to content

Instantly share code, notes, and snippets.

@g-maclean
Created January 7, 2026 22:09
Show Gist options
  • Select an option

  • Save g-maclean/2deb0306c121fecd5da6eea55426b341 to your computer and use it in GitHub Desktop.

Select an option

Save g-maclean/2deb0306c121fecd5da6eea55426b341 to your computer and use it in GitHub Desktop.
Property Hive - redirect off market property URLs
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