Last active
November 3, 2017 16:13
-
-
Save maxyudin/cf15344404988f657816956f412f105e 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', 'mxbd_filter_listings_by_smth' ); | |
function mxbd_filter_listings_by_smth() { | |
if (isset($_GET['post_type']) && 'listing' == $_GET['post_type']) { | |
$selected_cat = isset($_GET['listing_cat']) ? $_GET['listing_cat'] : ''; | |
wp_dropdown_categories(array( | |
'show_option_all' => __('All Categories', 'mxbd'), | |
'taxonomy' => 'listing_cat', | |
'name' => 'listing_cat', | |
'orderby' => 'name', | |
'selected' => $selected_cat, | |
'show_count' => true, | |
'hide_empty' => false, | |
'value_field' => 'slug', | |
// 'hierarchical' => 1, | |
)); | |
$selected_user = isset($_GET['u_name']) ? $_GET['u_name'] : ''; | |
wp_dropdown_users( array( | |
'show_option_all' => __('All Authors', 'mxbd'), | |
'name' => 'u_name', | |
'selected' => $selected_user, | |
)); | |
} | |
} | |
add_filter( 'parse_query', 'mxbd_modify_query_to_filter_by_smth' ); | |
// (wp_query object) $query | |
function mxbd_modify_query_to_filter_by_smth( $query ) { | |
global $pagenow; | |
if ( isset($_GET['post_type']) | |
&& 'listing' == $_GET['post_type'] | |
&& is_admin() | |
&& $pagenow == 'edit.php') { | |
if(isset($_GET['u_name']) && $_GET['u_name'] != '') { | |
$query->query_vars['author'] = $_GET['u_name']; | |
} | |
if(isset($_GET['u_name']) && $_GET['listing_cat'] != '') { | |
$query->query_vars['listing_cat'] = $_GET['listing_cat']; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment