1

I'm building a content slider that needs to show posts from a custom post type called "Features," and also show standard blog posts that are assigned to a "Featured" category. I'd like to do this within a single loop. Can anyone help me put together the query that could handle this?

1
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

query_posts( array(
        'post_type' => array(
                    'post',
                    'features',

                ),
'category_name' => 'Featured',
                'paged' => $paged )

            );

// have some posts?
if (have_posts()) :
    while (have_posts()) : the_post();

        // the loop

    endwhile;
endif;
?>
  • you can also use 'posts_per_page' => -1 to display all posts – Daniel Sachs Jun 13 '11 at 14:56
  • Works great! However, this query assumes that the custom post type will also be of the category 'Featured'. I solved this by enabling the default categories for the custom post type as well so I can assign them to the 'featured' category. For future reference, is there a way around that within this query? – pwbred Jun 13 '11 at 16:06
  • 1
    By default Wordpress assumes AND on SELECT queries. To use OR you'll need to use custom SELECT Displaying_Posts_Using_a_Custom_Select_Query – Daniel Sachs Jun 13 '11 at 16:52
0

Fix paging issues:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

Query to add in custom post types:

query_posts( array(
        'post_type' => array(
                    'post',
                    'custom_post_type_name'
                ),
                'paged' => $paged ) 
            );

Start the main loop

if (have_posts()) :
    while (have_posts()) : the_post();

            //Post content

    endwhile;
endif;
?>

Your Answer

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

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