Skip Navigation

[Resolved] Taxonomy term order with primary category from Yoast

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to show a list of terms associated with each post in a loop. I would like to order the terms so that the primary category appears first.

Solution: The primary category designation is a Yoast SEO feature, and unfortunately Toolset's sorting algorithms are not designed to sort using this criteria. This would require custom programming.

Relevant Documentation:
https://yoast.com/yoast-seo-3-1/
https://kb.yoast.com/kb/yoast-wordpress-seo-titles-metas-template-variables/

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by jesseH-3 6 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#860129

I am trying to display multiple categories with the primary category first.
I can only list them in ascending or descending order; I do not see a way to list the primary first.

Link to a page where the issue can be seen: hidden link
Example: Photography & Prose (In some cases, Prose is the primary and Photography is the secondary. But they are always shown in ABC order regardless of the primary designation.)

#861128

Hi, can you give me some more details about what you mean by "primary" and "secondary" categories? This terminology isn't familiar to me. Is primary/secondary a designation specified in another plugin, or some custom field system you have set up in Types?

#862064
Screen Shot 2018-05-08 at 3.47.12 PM.jpg

I'm pretty sure it's part of the WordPress core (though a fairly recent addition): if a post is assigned to more than one category (or other category-like taxonomy), it gives the option of setting one of them as the primary category.
In this case, I have a taxonomy "Format" that behaves much like a category. See attached screen grab showing that one of them is designated as the "primary" one.

#862416

Okay I did some more investigation and it turns out this is a Yoast SEO feature:
https://yoast.com/yoast-seo-3-1/

I'm able to see that Yoast adds a hidden field in the postmeta table that contains the ID of the primary term in each taxonomy. Unfortunately the wpv-post-taxonomy shortcode isn't designed to be able to sort by this criteria. I think this type of sorting would have to be accomplished with custom code, which falls outside the scope of the support we provide here. You might be able to find some information about this on the Yoast site - maybe they offer a custom shortcode you can use to do something similar, ordered by their proprietary information. You could check with their support team for more information about that.
https://kb.yoast.com/kb/yoast-wordpress-seo-titles-metas-template-variables/

#862893

Thank you so much, I assumed that was a core WP feature and didn't realize it was coming from Yoast. I'll look into this from that direction instead.