• Loop like this…

    global $query_string;
        $posts = query_posts($query_string . 'posts_per_page=3&post_type=music');
        if (have_posts()) : while (have_posts()) : the_post();

    …works great! Keeps the original query around and pagination works. But it has all the post types in it. I have 4 custom post types. I would like to exclude the pages.

    This loop display the custom post types and posts, but not pages. But…

    query_posts(array('posts_per_page' => 3, 'post_type' => array('recommendations', 'posts', 'photos', 'food', 'music')));
        if (have_posts()) : while (have_posts()) : the_post();

    …the $query_string won’t work when using the array method. Like it says here

    If you don’t need to use the $query_string variable, another method exists that is more clear and readable, in some more complex cases. This method puts the parameters into an array.

    Thanks for all the help 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • If you’re just looking for pagination to work and don’t need the entire query string:

    query_posts( array( 'posts_per_page' => 3, 'post_type' => array( 'recommendations', 'posts', 'photos', 'food', 'music' ), 'paged' => get_query_var( 'paged' ) ) );
    
    if ( have_posts() ) : while( have_posts() ) : the_post();

    If it doesn’t work, you can also try the query variable “page” instead; it can depends on where the query is located.

    'paged' => get_query_var( 'page' )

    If you need the query string preserved, you can try this. I’ve never tested it, so I’m not entirely sure that it works though.

    global $query_string;
    $posts = query_posts( $query_string . '&posts_per_page=3&post_type=recommendations,posts,photos,food,music' );
    
    if ( have_posts() ) : while( have_posts() ) : the_post();
    Thread Starter hilj

    (@hilj)

    Actually I don’t need the original query, it just enabled the pagination to work. The first loop you posted does just that and works great, thanks!!!

    The post_type needs to be in array form. This wont work.

    query_posts( $query_string . 'post_type=recommendations,posts,photos,food,music' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘A LOOP with multiple custom post types and $query_string’ is closed to new replies.