147 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
FlexiPress says

I had the same problem once and I wrote about it here in the forums: http://themeforest.net/forums/thread/custom-post-types-pagination-and-404-not-found-pages/32264 Could it be that you have the same problem?

no, it is different problem…

i did check Ollie’s theme, so, we talked about custom taxonomy archive pages, not a page template… :D it is totally different… ;)

the code above is useful when we run custom query in a page template, like what you do to display custom post types… not taxonomy archives page

so, three lesson from here…
1) don’t use ‘exclude_from_search’ => true when registering your public post type, if you need to display it in archive page.
2) don’t register custom taxonomy with priority lower than priority for registering associated post type. ollie register taxonomy using priority 0, and register post type using priority 10 (default).
3) no need to run custom query on taxonomy/category/post_tag archive page, that will break your pagination.

I am only a wordpress newbie, so CMIIW …

129 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Located in Ireland
  • Made it to the Authors' Hall of Fame
+5 more
OllieMcCarthy says


I had the same problem once and I wrote about it here in the forums: http://themeforest.net/forums/thread/custom-post-types-pagination-and-404-not-found-pages/32264 Could it be that you have the same problem?

no, it is different problem…

i did check Ollie’s theme, so, we talked about custom taxonomy archive pages, not a page template… :D it is totally different… ;)

the code above is useful when we run custom query in a page template, like what you do to display custom post types… not taxonomy archives page

so, three lesson from here…
1) don’t use ‘exclude_from_search’ => true when registering your public post type, if you need to display it in archive page.
2) don’t register custom taxonomy with priority lower than priority for registering associated post type. ollie register taxonomy using priority 0, and register post type using priority 10 (default).
3) no need to run custom query on taxonomy/category/post_tag archive page, that will break your pagination.

I am only a wordpress newbie, so CMIIW …

:D Wow! What can I say – my faith in humanity is restored! To think of the all hours and hours I spent banging my head against the wall over that.

All I can say is this man is a scholar and a gentleman and I am incredibly grateful.

Thanks again :D

147 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
FlexiPress says

thanks, I am happy to help you ;)

63 posts
  • Has been part of the Envato Community for over 3 years
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Had an item featured in an Envato Bundle
  • Has collected 1+ items on Envato Market
+3 more
DMThemes says

Give PrimaThemes forum super star badge right now!!!1 You don’t see this kind of help everyday! :)

204 posts Bold WordPress Theme Development
  • Has been part of the Envato Community for over 6 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Interviewed on an Envato blog
+5 more
srhnbr says

so, three lesson from here…
1) don’t use ‘exclude_from_search’ => true when registering your public post type, if you need to display it in archive page.
2) don’t register custom taxonomy with priority lower than priority for registering associated post type. ollie register taxonomy using priority 0, and register post type using priority 10 (default).
3) no need to run custom query on taxonomy/category/post_tag archive page, that will break your pagination.

Thanks for sharing :)

3256 posts
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+9 more
ParkerAndKent says

Guys,

when you are displaying results for a custom taxonomy (taxonomy archives, like categories archives) the pagination breaks because in that situation WP uses the posts_per_page value set for the blog in the reading settings, but returns the max pages and current page calculated for the posts_per_page used for the custom taxonomy… so that’s why the 404 pages. WP tells you that there are more pages, but that’s not true.

This bug happens only when we set different posts_per_pages, so it’s hard to catch… I’ve debugged everything for weeks.

The solution, in any case, is simple. It’s enough to change the posts_per_page value of the query with the pre_get_posts filter, in this way the query uses the correct values for our custom taxonomies.

This is the function i use for my framework, feel free to edit it for your needs:

function pk_pre_get_posts($query) {

    if (is_admin()) {

        return $query;

    }

    if (is_tax('taxonomy_works') || (function_exists('is_post_type_archive') && is_post_type_archive('works'))) {

        $query -> set('posts_per_page', $posts_per_page);

    }

    return $query;

}

add_filter('pre_get_posts', 'pk_pre_get_posts');

The var $posts_per_page holds the posts_per_page value of the custom taxonomy, so you need to valorize it by yourself.

Parker

1 post
  • Has been part of the Envato Community for over 4 years
  • Has collected 10+ items on Envato Market
  • Located in France
guigoz says

@PrimaThemes you’re my hero !!!!!! Thanks.

92 posts
  • Has been part of the Envato Community for over 1 year
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
QUAL says

The solution, in any case, is simple. It’s enough to change the posts_per_page value of the query with the pre_get_posts filter, in this way the query uses the correct values for our custom taxonomies.

Sorry for replying a very old topic, but I needed to ask:

can we still use add_action(“pre_get_posts”... to change the number of posts in home, category and search results?

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by