Thanks Luo,
"I assume you are going to add a pagination limitation dropdown into the search form, and change the "posts_per_page" parameter of WordPress Archive page."
Not quite.
I don't want to add a dropdown for users of the page to select how many posts to show per page, I simply want to select a number higher than 39 when designing my archive page for how many posts to show per page when I turn on pagination.
When I design the archive page, and select how many posts to show per page, I have only the option to display up to 39 posts.
I want to simply increase that number, so that my archive page, when it first loads, will display for example 75 posts per page.
I think it must be a solution similar to the code you have just written, only it will not change the search form at all.
You can change the the WordPress Archive page "posts_per_page" parameter default value by this:
Dashboard-> Settings-> Reading, option "Blog pages show at most".
You can also use custom codes to change it like this:
add_action('pre_get_posts', function($query){
if ( ! is_admin() && $query->is_main_query() && is_post_type_archive( 'test-cpt-1' ) ) { // replace 'test-cpt-1' with your custom post type slug
$query->set( 'posts_per_page', 123 ); // here replace 123 with the number you want
}
},99);
Thanks Luo,
I tried adding this code with the Code Snippets plugin.
It doesn't seem to work.
First of all, this isn't a general archive for my custom post type; these are archives specific to a taxonomy of the custom post type.
I tried the general custom post type slug, "location", this didnt work.
Then I tried to URL slug of the specific taxonomy, and the individual archive pages "near-me/taxonomy1"; this also didn't work..
On my archive template design page I should enable pagination correct? Or anything specific I need to set here?
And is there something that must be added to the code you posted above to make it work for my specific taxonomy archive?
Thanks for the help, we're getting there 🙂
Please share your website credentials in below private message box, also point out the problem page URL and where I can edit your custom PHP codes, I need a live website to test and debug it, thanks
Found the solution.
For other people looking on how to do this,
add_action('pre_get_posts', function($query){
if ( ! is_admin() && $query->is_main_query() && is_tax( $taxonomy = 'taxonomyname', $term = 'termname' ) ) { // replace 'test-cpt-1' with your custom post type slug
$query->set( 'posts_per_page', 75 ); // here replace 123 with the number you want
}
},99);
Just replaced the is_post_type_archive with is_tax in the code you provided, thanks.
This allows you to target the archive that you create for a specific taxonomy and a specific term/tag within that taxonomy it seems.
Replace the "taxonomyname" and "termname" with the URL slug for each of those and voila.
Now I'm just trying to figure out how to speed up the page at all; and since it seems like there really isn't any way to do this; trying to figure out how to default start on one state so that intuitively users pick their state resulting in needing to load less posts at once.
I have another support thread open about that, any ideas I would be really happy to hear them! 🙂
Thanks!
G