Last active
October 23, 2024 11:11
-
-
Save propertyhive/54b0c5eba5422fee9a5e9ee24b1c58cb to your computer and use it in GitHub Desktop.
This file contains 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('pre_get_posts', 'to_let_only_by_default'); | |
function to_let_only_by_default($q) | |
{ | |
if (is_admin()) | |
return; | |
if (!$q->is_main_query()) | |
return; | |
if (!$q->is_post_type_archive('property') && !$q->is_tax(get_object_taxonomies('property'))) | |
return; | |
if (isset($_GET['shortlisted'])) | |
return; | |
if (isset($_GET['department']) && $_GET['department'] == 'residential-lettings') | |
{ | |
$tax_query = $q->get('tax_query'); | |
$tax_query[] = array( | |
'taxonomy' => 'availability', | |
'field' => 'term_id', | |
'terms' => array(123), // CHANGE 123 FOR 'To Let' ID. THIS CAN BE FOUND UNDER 'Property Hive > settings > custom Fields > Availabilities' | |
'operator' => 'IN' | |
); | |
$q->set('tax_query', $tax_query); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment