Support » Plugin: Ambrosite Next/Previous Post Link Plus » in_same_tax for non-hierarchical

  • Resolved divydovy


    Hi @ambrosite, thanks for the plugin and extensive support you give.

    in_same_tax looks like it’s specifically designed not to work with non-hierarchical taxonomies e.g. tags.

    I guess that’s intentional and there’s a good reason for it.

    I needed it to make it work so removed the array_filter from line 901 (to give $taxonomies = get_post_taxonomies($post->ID);)

    I’m posting this:
    (a) to say that it would have been useful if in_same_tax did support flat taxonomies
    (b) to help anyone else with the same issue
    (c) to ask you if this is going to break things in ways I’m not foreseeing.



Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author ambrosite


    The reason for not supporting tags is very simple: Typically people put more than one tag on their posts. As soon as the plugin hits a post with multiple tags, it will get confused and display links for all the tags, not just the “current” tag. Rather than deal with hundreds of messages from people asking, “Why doesn’t the plugin work on posts with multiple tags?”, I simply removed the support for tags completely.

    But yes, if someone insists on making it work with non-hierarchical taxonomies, they can do it very easily by making the change you described (and I think you meant line 91, not 901).

    Thanks @ambrosite for taking the time to explain/respond.

    Yes, line 91 doh.

    Feedback if it’s helpful is that it’d be easier to understand if:

    – the plugin clearly states that in_same_cat works only for categories and not tags by default
    – but if you want to use tags then treat it as a custom taxonomy

    If people are asking to use a custom taxonomy then it’s likely they’re either aware of it being flat and how it’s used in the site OR (as with my case) I’m using a custom tax/post type generated by a plugin where I don’t have the luxury of using a hierarchical tax.

    If you’re open to collaboration I could do my best to fork and pull request on Github.

    Hope this is helpful and appreciate the plugin/support. Cheers!

    Plugin Author ambrosite


    And now you are one more person asking, “Why doesn’t it work on posts with multiple tags?” 🙂

    Look, I don’t mind having this conversation with someone who is technically savvy enough to understand the explanation, and it sounds like maybe you are savvy enough, so let me ask you … why do you think it doesn’t work? How does the plugin determine which taxonomy term is the current term? (Hint: examine lines 105 and 114-116.)

    Thanks for your time.

    Tried to hit you on Skype but here goes for public bravery. If I understand your question, you’re asking how the query knows which term to use to match the prev/next post to.

    It looks like the $in_same_term_sql is an array of all the cat or tax term ids, optionally with any post_format id’s too.

    Is the answer then that running an IN on a whole bunch of tag term IDs at once is (a) going to hammer MySQL and (b) produce few results because the more tags there are, the fewer matches there will be?

    Sorry if I’m missing the point…

    Plugin Author ambrosite


    Let me explain the problem another way. Suppose I have a series of posts, with taxonomy terms (tags, categories, whatever) assigned as follows:

    Apple (fruit)
    Banana (yellow, fruit)
    Bus (yellow, vehicle)
    Car (vehicle)
    Pear (fruit)

    If you start out on Apple, and the in_same_tax parameter is set, then you would expect the navigation sequence to be this:

    Apple -> Banana -> Pear

    But instead you might end up with this:

    Apple -> Banana -> Bus -> Car

    Do you see the problem? When you get to a post with multiple terms, the plugin cannot tell which term is the correct term. For example, Banana is tagged with both ‘yellow’ and ‘fruit’, therefore Bus and Pear are both valid next posts.

    Most people would say, I started out on Apple, and that post was tagged ‘fruit’, therefore ‘fruit’ is the current term, and Pear should be the next post. But how is the plugin supposed to know which term is current?

    Sure. I get that. I think we’re talking cross-purposes a little here but I really appreciate your time.

    All I’m saying is that I’d have found it really helpful to be able to define in_same_tax as a custom taxonomy that’s non-hierarchical. I get that including tags or multiple taxonomies at once would confuse people.

    But I don’t have to develop or support the plugin so I totally respect your reasoning, time and coding skillz. Thanks again.

    Plugin Author ambrosite


    You’re welcome. My only purpose in all this was to explain that, if I could solve the problem I described, then I would be happy to support non-hierarchical taxonomies. But since I don’t have a solution at the moment, and since non-hierarchical taxonomies won’t work the way most people expect, I have chosen not to support them.

    But like I said at the beginning, if someone really wants to make it work, they can do the simple hack you described in your opening post.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘in_same_tax for non-hierarchical’ is closed to new replies.