Skip Navigation

[Resolved] Sort Custom Taxonomy by a custom field.

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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 4 replies, has 2 voices.

Last updated by roniseS 9 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#237885

I have used the wp-types solution to build a small directory of vendors. All vendors (custom post are under a custom taxonomy). I want to display a list of the taxonomies (vendors categories) and once you click on a vendor category display all vendors under the same classification, but I want to order them by the package their pay for (basic, enhanced and premium).

I got everything working, except for the order of the taxonomy...

#237928

Hi roniseS,

Are you going to order the archive page of taxonomies (vendors categories) by custom field "the package their pay for"?
Please try the solution in another thread:
https://toolset.com/forums/topic/sort-custom-post-archive-by-custom-field/

#239853

Hello, Thanks for your response,

I am still having trouble, because my custom field is not numerical is a radio field with three options.

#240157

Please try add codes in your theme functions.php. like this:

function sort_vendors_archive_loop($query) { 
    if ($query->is_post_type_archive('vendors') && $query->is_main_query()) {
    $query->set('order', 'ASC');
    $query->set('meta_key', 'wpcf-pay-for');
    $query->set('orderby', 'meta_value');
    }
}
add_action('pre_get_posts', 'sort_vendors_archive_loop');

Please replace "vendors" with the custom post type slug of "vendors"
And replace "pay-for" with the slug of custom field "the package their pay for"

More help:
http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

#244019

Thank you!

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.