So I made some custom posts and taxonomies..


Till here, all fine: I get a 'mytaxonomyterm' taxonomy archive. Btw, lang is because I'm using polylang plugin.

If I try to add &posts_per_page=15 to url, it doesn't work: it won't change number of post.

Even worse, if I add paged=1, It will reload into http://example.com/?product_category=mytaxonomyterm&lang=it (so stripping the page param).

Even worse, if I add paged=1, it will throw an error telling me that there's an error in post-template.php on line 279, 'Trying to get property of non-object'.

So what? What am I doing wrong?

  • What do you mean by "adding" those parameters? Are you editing the string in the browser address bar? Or trying to construct links in the PHP? – s_ha_dum Dec 28 '15 at 16:34
  • To try, I'm just adding to the browser. But what's the point with my question? The problem is the results, not where you write the query. I guess. Thank you. – Luca Reghellin Dec 28 '15 at 17:25
  • What matters, first, is whether you are generating the correct string, so, yes, how you are doing it is important. – s_ha_dum Dec 28 '15 at 17:35

If I try to add &posts_per_page=15 to url, it doesn't work: it won't change number of post.

I wonder if you're looking for a custom query variable, e.g. ppp, to change the number of posts for the main query:

add_filter( 'query_vars', function( $vars )
  $vars[] = "ppp";
  return $vars;
} );

add_action( 'pre_get_posts', function( \WP_Query $q )
    if( ! is_admin() && $q->is_main_query() )
        $ppp = $q->get( 'ppp' );
        if( ! empty( $ppp ) && 20 >= (int) $ppp )
            $q->set( 'posts_per_page', (int) $ppp );
} );

where we limit the maximum number of posts to 20. You could then restrict this further if needed.

What am I doing wrong?

The posts_per_page is a private query variable in the WP class, so you will not be able to use it as a GET parameter in your request, to modify the main query.

The paged is a public query variable, so you can access that one.

  • +1 for the posts_per_page being private :), I didn't notice. Anyway, as you wrote, paged is public so should't I be able to pass it on the url? es &paged=2? It currently doesn't work (and yes, I created enough posts for 3+ pages). – Luca Reghellin Dec 28 '15 at 18:07
  • Did you try it out on the default theme? Maybe the error issue with paged is theme or plugin related? Do you have permalinks off ? @Stratboy – birgire Dec 28 '15 at 18:14
  • Since I'm currently speaking of custom taxonomies, I cannot use the default theme. I'm using mine (I don't use thirdy parts things), but it's really bare bones for now. Permalinks are temporarily off, but I had same results even with perma-on. Basically, when adding paged=2, the dispatcher will route to a wrong template and will not populate variables. The error is coming out of post-template.php, searching for $post->post_content, but $post is NULL, hence the non-object error. It should be an archive, though.. Just like it currently IS without the paged var. – Luca Reghellin Dec 29 '15 at 7:25
  • Update: I found out in fact it goes to a 404, and the $post error was correct since I had called the_content() inside the 404 template. Still I can't figure out WHY it ends up on a 404 as soon as I add a paged variable. – Luca Reghellin Dec 29 '15 at 7:32
  • ok, it suddenly started to work.. Don't know... getting mad. – Luca Reghellin Dec 29 '15 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.