I want the defult CPT listing to include not all posts but only some, according to a specific taxonomy. is there a way to do that ?
1 Answer
This trick should help you...
<?php
add_action('pre_get_posts', 'filter_posts_list');
function filter_posts_list($query)
{
//$pagenow holds the name of the current page being viewed
global $pagenow;
$post_type = $query->get('post_type');
//Check the post type and whether its the list page, then set the taxonomy
if($post_type == 'my_cpt' && 'edit.php' == $pagenow)
{
//global $query's set() method for setting the taxonomy
$query->set('my_taxonomy', 'my_taxonomy_value');
}
}
?>
You can use any WP_Query parameters with the set
method to modify this solution. For a detailed explanation, hit this.
-
one error in the if up there. couldn't edit coz it's just one char Mar 7, 2012 at 14:09
-