Last active
May 5, 2017 04:14
-
-
Save enqtran/3e9d44b331f7c65dc45f0b0326bca098 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
<?php | |
if (!function_exists('post_type_filters')) { | |
function post_type_filters() | |
{ | |
global $typenow; | |
if ($typenow == 'plans' || $typenow == 'reviews' || $typenow == 'news') { | |
$posts = get_posts(array('numberposts' => -1)); | |
echo '<select name="shopid">'; | |
echo '<option value="">All Shop</option>'; | |
foreach ($posts as $post) { | |
echo '<option value="' . $post->ID . '">' . $post->post_title . ' </option>'; | |
} | |
echo '</select>'; | |
wp_reset_postdata(); | |
} | |
} | |
add_action('restrict_manage_posts', 'post_type_filters'); | |
} | |
if (!function_exists('get_filter_post_id')) { | |
function get_filter_post_id($query) | |
{ | |
global $typenow; | |
global $pagenow; | |
if ($pagenow == 'edit.php' && $typenow == 'plans' && isset($_GET['shopid'])) { | |
$query->query_vars['meta_key'] = 'choise_shop'; | |
$query->query_vars['meta_value'] = (int)$_GET['shopid']; | |
} | |
if ($pagenow == 'edit.php' && $typenow == 'reviews' && isset($_GET['shopid'])) { | |
$query->query_vars['meta_key'] = 'choise_shop_reviews'; | |
$query->query_vars['meta_value'] = (int)$_GET['shopid']; | |
} | |
if ($pagenow == 'edit.php' && $typenow == 'news' && isset($_GET['shopid'])) { | |
$query->query_vars['meta_key'] = 'choise_shop_news'; | |
$query->query_vars['meta_value'] = (int)$_GET['shopid']; | |
} | |
} | |
add_filter('parse_query', 'get_filter_post_id'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment