WordPress Show All Posts on a Custom Post Type Archive Page

7 Comments

  1. Dan

    Is there a way of filtering out one of the authors from this scheme? Let’s say a user with the ID=’4′ doesn’t want to have an author archive with portfolios, but only with plain posts. Is it possible?
    Thank you.

    1. Hi Dan,

      Not quite following you here. Are you looking to filter a user out of the portfolio archive, or simply show ALL posts by an author?

      You can also use pre_get_posts to show all posts on an author archive page. Try this in the query: if ( $query->is_author() ) {...}

  2. Hi!

    We’re facing the same problem now. The issue is that WordPress in spite of using $query->set(‘posts_per_page’, -1 ); or set_query_var(‘posts_per_archive_page’, -1); still process archive pages!

    For example, you need to make single archive page for all the posts you have there:
    example.com/movies

    and you set posts_per_page -1 in your functions.php, but wordpress will still process and return pages:
    example.com/movies/page/2, example.com/movies/page/3 etc.

    Now, I’m trying to find out the solution.
    If you’ll got some – please write a reply here, I’ll check notify.

    1. Hi Rubika. By setting posts_per_page to -1 you are telling WordPress to show all posts.

      If you are trying to prevent WordPress from creating an archive for a custom post type, you’ll need to set has_archive to false.

      I hope that helps.

      1. Rubika

        No, the main idea is to keep archive page but prevent existing pagination pages that WordPress keep processing with direct access. For example:
        example.com/portfolio/page/2

        Solved with detecting ‘page’ variable and send 404 headers

  3. RunPower

    To show all the CPT s elementor wants your to use one of their archive widgets. This gives you options on how to display the archive, however what this widget does is show a collection of mini previews to the CPT s like what you see when you create a blog.

    1. Hi RunPower. If you’re using Elementor to show page archives, the snippet above will be of little use to you.

Leave a Reply

Your email address will not be published. Required fields are marked *