Created
November 24, 2021 23:06
-
-
Save ahmadthedev/4c0a7228dce35a40a428a334ff7e789e to your computer and use it in GitHub Desktop.
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
<?php | |
add_action('restrict_manage_posts','ahmeddev125_restrict_properties', 10, 2); | |
function ahmeddev125_restrict_properties( $post_type, $which ) { | |
if( 'properties' !== $post_type ) { | |
return; | |
} | |
$taxonomies = array('states', 'counties'); | |
foreach( $taxonomies as $tax_slug ) { | |
$tax_obj = get_taxonomy($tax_slug); | |
$tax_name = $tax_obj->labels->name; | |
$terms = get_terms($tax_slug); | |
echo "<select name='$tax_slug' id='$tax_slug' class='postform'>"; | |
echo "<option value=''>All $tax_name</option>"; | |
foreach ($terms as $term) { | |
echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>'; | |
} | |
echo "</select>"; | |
} | |
echo "<select name='p-status' id='p-status' class='postform'>"; | |
echo "<option value=''>All</option>"; | |
echo "<option ". ($_GET['p-status'] == 1 ? 'selected="selected"' : '') ." value='1'>For Sale</option>"; | |
echo "<option ". ($_GET['p-status'] == 2 ? 'selected="selected"' : '') ." value='2'>Sold</option>"; | |
echo "</select>"; | |
} | |
add_filter( 'parse_query', 'ahmeddev125_filter_request_query' , 50); | |
function ahmeddev125_filter_request_query( $query ) { | |
if( !( is_admin() AND $query->is_main_query() ) ) { | |
return $query; | |
} | |
if( 'properties' !== $query->query['post_type'] ) { | |
return $query; | |
} | |
if( isset($_GET['p-status']) ) { | |
$term = $_GET['p-status']; | |
if( !empty( $term ) ) { | |
if( $term == 1 ) { | |
$val = 'For Sale'; | |
} elseif( $term == 2 ) { | |
$val = 'Sold'; | |
} | |
$query->query_vars['meta_query'] = [ | |
[ | |
'key' => 'status_general_properties', | |
'value' => $val | |
] | |
]; | |
} | |
} | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment