[Résolu] how can i orderby custom post_types in views?
This support ticket is created Il y a 7 années et 5 mois. 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I am trying to: order the view by custom post_type
like:
post_type_1
post_type_1
post_type_1
post_type_2
post_type_2
post_type_2
post_type_3
post_type_3
post_type_3
post_type_3
without creating a special types field for the order issue.
hi minesh,
thank you. this is the simplest solution 🙂 i know. but what if i have more then one page or if i use infinite scrolling. i know i need a function but i dont know how.
thank you again
adnan
for the search i use this one and this works for the search results
add_filter('posts_orderby', 'group_by_post_type', 10, 2);
function group_by_post_type($orderby, $query) {
global $wpdb;
if ($query->is_search) {
return $wpdb->posts . '.post_type ASC';
}
// provide a default fallback return if the above condition is not true
return $orderby;
}
add_filter('wpv_filter_query', 'func_wpv_filter_query', 10, 3);
function func_wpv_filter_query( $query_args, $view_settings, $view_id ) {
// adjust this condition to decide when to apply the filter
if ($view_id == 9999) {
add_filter('posts_orderby', 'add_custom_order');
}
return $query_args;
}
function add_custom_order($order) {
global $wpdb;
return $wpdb->posts . '.post_type ASC';
}
Where:
Replace '9999' with your view ID.
You can adjust your code as needed and please note that this is a custom programming and that is out of the scope of our support policy. If you need custom programming for your site, Please feel free to contact us our certified partners:
=> https://toolset.com/consultant/