Skip Navigation

[Resolved] Show all (or more than 39) entries on map

This thread is resolved. Here is a description of the problem and solution.

Problem:

Specific WordPress Archive page pagination limitation with custom codes.

Solution:

See the example codes here:

https://toolset.com/forums/topic/show-all-or-more-than-39-entries-on-map/#post-2285363

Relevant Documentation:

This support ticket is created 2 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 19 replies, has 4 voices.

Last updated by graemeH-3 2 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#2286179

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.

#2286343

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);
#2287373

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 🙂

#2287475

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

#2289161

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

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.