Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
one error in the if up there. couldn't edit coz it's just one char –  hannit cohen Mar 7 '12 at 14:09
    
Ohh... typo... fixed it! –  Rutwick Gangurde Mar 7 '12 at 14:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.