147 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 10 and 49 users
  • Sold between 250 000 and 1 000 000 dollars
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 …

124 posts
  • Ireland
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 5-6 years
  • Bought between 50 and 99 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
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
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 10 and 49 users
  • Sold between 250 000 and 1 000 000 dollars
FlexiPress says

thanks, I am happy to help you ;)

63 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 3-4 years
  • Sold between 50 000 and 100 000 dollars
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
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 5-6 years
  • Interviewed on the Envato Notes blog
  • Referred between 200 and 499 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+1 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
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
+4 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
  • Bought between 10 and 49 items
  • France
  • Has been a member for 4-5 years
guigoz says

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

62 posts
  • Bought between 10 and 49 items
  • Has been a member for 1-2 years
codepanels 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?

by
by
by
by
by
by