-2

I am using next_post_link() , and I want to use the parameters shown in the documentation to restrict it to go to the next post with the same term for a custom taxonomy called "years".

The line I am using is

<?php next_post_link( '%link', __( 'Next', 'twentyeleven' ), TRUE, '', 'years' ); ?>

This does not display a "next" link at all. However, when I remove the optional parameters, it does display the "next" link.

The page in question is http://stage.newurbanarts.org/mentors/alejandra-peralta/ (htaccess username: guest / password: stackexchange).

I put some debugging code into it near the top to show the output of the_taxonomies() and the_terms().

It should show the "Next" link which would go to http://stage.newurbanarts.org/mentors/alison-rutsch/ - note in the debugging code that this post has the same terms for "years".

Update: I enabled some debugging - printing all the warnings on the page resulted in the page being unintelligible with many warnings coming from various plugins. I put all the info into this log file, and the screen now displays where the "next" link should be:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') WHERE p.post_date > '2013-09-30 12:05:35' AND p.post_type = 'mentors' AND p.po' at line 1] SELECT p.* FROM wp_posts AS p INNER JOIN wp_term_relationships AS tr ON p.ID = tr.object_id INNER JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category' AND tt.term_id IN () WHERE p.post_date > '2013-09-30 12:05:35' AND p.post_type = 'mentors' AND p.post_status = 'publish' AND tt.taxonomy = 'category' ORDER BY p.post_date ASC LIMIT 1

===

WordPress 3.4.1 (It's an old site that I just picked up for an organization that has not updated it for a while. Depends on many old plugins, so upgrading may break things, but I will give that a shot as per the answers.)

Full code on github.

Also, here's just the template file in question.

  • The excluded_terms param should be just '', not a space ' ' – bonger Aug 10 '15 at 17:59
  • @bonger I removed the space and updated the question and the staging server. Still getting the same result. – Mike Eng Aug 10 '15 at 22:00
  • Mmm, very odd, just tried adding the same next_post_link() to one of my own sites with a custom taxonomy and it worked - but I see you're debugging it so I'll leave you to it!... – bonger Aug 10 '15 at 22:53
  • @bonger thanks. Not sure how to fix the SQL syntax from the error. I updated the question with said wordpress error. Let me know if you have ideas on that. My SQL knowledge is not great. – Mike Eng Aug 10 '15 at 22:57
  • 2
    3.4.1, Really? I don't want to sound rude or anything, but you are light years behind and missing out on some great features – Pieter Goosen Aug 13 '15 at 15:49
5
+50

Back with WordPress 3.4.1 the function next_post_link() did not have - see source - the $taxonomy parameter, so it won't work, no matter what. IIRC the parameter is available since WP 3.8 or 3.9 - but those are pretty old too.

Just to say that very clearly, do NOT use such a old version(s) of WP.

  • As for the generated SQL the empty IN () clause (... AND tt.term_id IN (__there_must_be_something_in_here__)...) is what causes it to fail. – webtoure Aug 13 '15 at 14:25
  • Rarely had a problem with the parameter, when used with a version that actually supports it. So this is the first step, should it not work afterwards, then we can talk further. @webtoure – Nicolai Aug 13 '15 at 14:28
  • Oh, my explanation was just in case anybody was curios (as I was) about it. :) Of course not using this old 3.4.1 version is the first step. It doesn't surprise me that these old versions are alive since a lot of people are also running PHP versions < 5.3.0 for "no reason" (it's about legacy code of course). – webtoure Aug 13 '15 at 14:34
  • Looking at the WordPress usage statistics makes me wonder in disbelieve every time.. @webtoure – Nicolai Aug 13 '15 at 14:39
  • 1
    I would say, you kind of have to, otherwise you only can implement a workaround of some sorts and it gets even messier. Do not forget to make a complete backup of the status quo, so all the files (WP,theme,plug-ins) and the database. Personally I would even say, get rid of - or replace - the things no longer compatible with the current version of WordPress. Because, all things considered, there is just no good reason for using such a outdated version. I know it is sometimes a hard sell to the clients, but not doing - or at least trying - it is kind of irresponsible. @MikeEng – Nicolai Aug 14 '15 at 16:57
-1

I was able to make it working by dropping the $excluded_terms = ''

next_post_link( '%link', __( 'Next', 'twentyeleven' ), true, '', 'years' );
next_post_link( '%link', __( 'Next', 'twentyeleven' ), true, 'years' );

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.