Skip to content

Instantly share code, notes, and snippets.

@propertyhive
Last active December 13, 2019 08:06
Show Gist options
  • Save propertyhive/7458aeb66b574cec8d9749b30840a844 to your computer and use it in GitHub Desktop.
Save propertyhive/7458aeb66b574cec8d9749b30840a844 to your computer and use it in GitHub Desktop.
Exclude certain office(s) from main results and shortcodes
add_action( 'propertyhive_property_query', 'remove_office_properties' );
function remove_office_properties( $q )
{
if ( !is_admin() && is_post_type_archive( 'property' ) )
{
$meta_query = $q->get( 'meta_query' );
$meta_query[] = array(
'key' => '_office_id',
'value' => array( 123 ), // CHANGE 123 to the office ID you wish to exclude
'compare' => 'NOT IN',
);
$q->set( 'meta_query', $meta_query );
}
}
add_filter( 'propertyhive_shortcode_properties_query', 'remove_office_properties_from_shortcodes', 10, 2 );
add_filter( 'propertyhive_shortcode_recent_properties_query', 'remove_office_properties_from_shortcodes', 10, 2 );
add_filter( 'propertyhive_shortcode_featured_properties_query', 'remove_office_properties_from_shortcodes', 10, 2 );
add_filter( 'propertyhive_shortcode_similar_properties_query', 'remove_office_properties_from_shortcodes', 10, 2 );
function remove_office_properties_from_shortcodes($args, $atts)
{
$args['meta_query'][] = array(
'key' => '_office_id',
'value' => array( 123 ), // CHANGE 123 to the office ID you wish to exclude
'compare' => 'NOT IN',
);
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment