hi and thanks for stopping by..
iI need to sort my search results by custom post type. the problem: the order is custom.
iI do have 5 different post types and i got the order like so:
- artist
- artwork
- page
- post
- publication
i'dI'd like the order to be like this:
- artist
- post
- artwork
- publication
- page
hereHere is, what i gotI have so far, the elements are grouped by their post type and get sorted by title. wonderfulWonderful. nowNow all iI need is the custom ordering. any
Any hint?
add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 2 );
function order_search_by_posttype( $orderby ){
global $wpdb;
if( ! is_admin() && is_search() ) :
$orderby = "{$wpdb->prefix}posts.post_type ASC, {$wpdb->prefix}posts.post_title ASC";
endif;
return $orderby;
}