1

I want to see all the posts on my WordPress blog which are tagged with foo.

If I visit https://example.com/blog/tag/foo - it shows me the default number of pages, 10, and an option to view more at the bottom.

Is there a URL parameter I can use to show all to posts? Or to show 15 posts?

If I use ?order=asc or ?order=desc I can change the order in which they are displayed. But if I use ?posts_per_page=100 nothing changes.

I don't want to install any plugins, or alter any code on my blog.

2
  • Does posts_per_page=-1 do anything? Commented Oct 6, 2018 at 10:43
  • Nope, sorry. -1 doesn't make a difference. Commented Oct 6, 2018 at 15:21

1 Answer 1

1

You could try the following :

add_action( 'pre_get_posts', function( \WP_Query $q )
{
    if( ! is_admin() && $q->is_main_query() )
    {
        $paged = abs((int)$_GET['post_per_page']);
        if( ! empty( $paged ) && $paged >= 1 ){
            $q->set( 'posts_per_page', $paged );
        } elseif($paged === 0){
            $q->set( 'posts_per_page', -1 );
        }
    }
} );

Here you can specify a post_per_page URL parameter to 0 if you want all posts, or an absolute INT if you want a specific number of post.

Note that this will apply on all non-admin main queries, so you might want to restrict editing the query to the page or page type you need.

If the default Wordpress pagination (page parameter) is not working, you can add something like

$q->set( 'paged', get_query_var( 'paged' ) ?: 1 );

Which can be used with ?paged=2 or /page/2 if you have proper rewriting.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, but as I said in the question, I don't want to alter any of the code on my site.
OK. It don't need any existing code edition. You just need to add this code to your function.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.