WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] 3.1 RC2 Adding any query to CPT archive removes archive functionality (3 posts)

  1. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    Here's something I just noticed, not sure if it's an intended behaviour/result of my lack of knowledge

    I had 3 CPTs, changed over all my CPT page templates to be archive-CPT.php and removed the queries. Turned on has archive, and all was right with the world.

    On one of my CPTs, I needed 30 posts per page, so I dropped a simple query into the archive template to display 30 posts. That had the unintended consequence of showing all posts.

    Seems if any simple query is used, the archive becomes an archive for all posts, not just the CPT any longer.

    Is there a different way to do it?

  2. Andrew Nacin
    Lead Developer
    Posted 3 years ago #

    If you're going to use query_posts(), you can't do this:

    query_posts('post_per_page=30');

    What that does is load up the normal posts! Instead, you'll want to append $query_string to your query_posts() call, or at least continue to pass a post_type=your_post_type.

    That said, changing the number of posts per page via query_posts is fraught with issues, because WordPress has already counted paging and such by that point. You'd be better to hook into request, parse_request, pre_get_posts, or even the posts per page value (for that post type) to specify pagination changes.

  3. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    Thanks for the intel! Learnin' every day!

Topic Closed

This topic has been closed to new replies.

About this Topic