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'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?

share|improve this question
add comment

2 Answers

$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;
?>
share|improve this answer
    
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? –  paulwhitman 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
    
Very helpful. Thank you. –  paulwhitman Jun 13 '11 at 18:04
add comment

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;
?>
share|improve this answer
add comment

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.