0

I know ways to add Custom Post Types to the default loop or feeds and ways to add custom post types to the default categories and tags, all involving 'pre_get_posts' filters. I was trying to do something related, yet more awkward: Adding Custom Post Types to the default post loop, but only post that do have any term from the default categories or tags assigned to them. Sort of if I'm seeing an archive of a category that includes all posts from the core "post" post type, plus a few other post from other post types.

Edit: I have resolved it in part (I wasn't getting results due to a dull typo):

    add_filter( 'pre_get_posts', 'my_get_posts_test_dos' );

    function my_get_posts_test_dos( $query ) {
    // Not sure if one needs too many conditionals, but still. Previously, the script was working without the opening and closing braces inside the if statement, but it was buggy just for that.
        if ( $query->is_post_type_archive('post') && $query->is_main_query()  && !$query->is_feed() && !is_admin()) {
   //  I'm naming manually some categories to include in the query. Althought for the   particular purpose is fine, I would need a simple way to just name *all* categories.
        $cat_a = get_cat_ID('category-one');
        $cat_b = get_cat_ID('category-two');
        $query->set( 'category__in', array($cat_a, $cat_b) );
        $query->set( 'post_type', array('post', 'video') );
        return;
        }
    }
  • Please tell us what research you have carried out, what you have tried (please post code) and what the result was. Thanks! – markcbain Jun 2 '14 at 5:20
  • Just added some code. – peroyomas Jun 2 '14 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.