Skip Navigation

[Resolved] sort output from view by taxonomy fields

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

Problem:

I need the posts to be sorted by field A within field B. The problem is that both field A and B are taxonomies. Is there a recommended workaround to achieve this?

Solution:

There isn't such a built-in feature to convert term fields to post fields, in your case, the post fields is required to sort the view's result.

So you might need to consider custom codes, for example:

https://toolset.com/forums/topic/sort-output-from-view-by-taxonomy-fields/#post-1096668

Relevant Documentation:

https://codex.wordpress.org/Function_Reference/get_posts

This support ticket is created 6 years, 3 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 6 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1096395

Tell us what you are trying to do?
Hi, I have a view to display child posts, I need the posts to be sorted by field A within field B. The problem is that both field A and B are taxonomies. Is there a recommended workaround to achieve this?
Alternatively would it be possible to convert (or copy) the taxonomy fields to custom fields or can I upload 2 extra fields where these taxonomies would now be custom fields?

Thanks for any help
david

#1096668

Hello,

There isn't such a built-in feature to convert term fields to post fields, in your case, the post fields is required to sort the view's result.

So you might need to consider custom codes, for example:
1) Setup two custom post fields
2) Create a custom function to convert term fields to post fields:
- Get all posts
https://codex.wordpress.org/Function_Reference/get_posts
Make a loop and do these:
- Get the terms attached each post
https://developer.wordpress.org/reference/functions/get_the_terms/
- Get the value of term fields of above terms
https://developer.wordpress.org/reference/functions/get_term_meta/
- Same those value into your custom post fileds:
https://developer.wordpress.org/reference/functions/update_post_meta/

For your reference.

#1097409

Hi Luo, Thanks for the advice.
What I did in fact was to add Fields A & B to the custom post as custom post fields, and reloaded the csv file of the child posts - that was the easiest solution for me.

#1098352

You are welcome