Ordering results by post type not working (with SF pro)
-
We’re using Relevanssi with Search & Filter Pro on our website. On the main search page, we’d like to sort the results by post type, prioritizing the products over posts and pages. I tried the following functions:
add_filter( 'relevanssi_comparison_order', 'rlv_post_type_order' ); function rlv_post_type_order( $order_array ) { $order_array = array( 'product' => 0, 'page' => 1, 'post' => 2, ); return $order_array; } add_filter( 'relevanssi_modify_wp_query', 'rlv_orderby' ); function rlv_orderby( $query ) { $query->set( 'orderby', 'post_type' ); return $query; }
and
add_filter( 'relevanssi_hits_filter', 'products_first' ); function products_first( $hits ) { $types = array(); $types['page'] = array(); $types['post'] = array(); $types['product'] = array(); // Split the post types in array $types if ( ! empty( $hits ) ) { foreach ( $hits[0] as $hit ) { array_push( $types[ $hit->post_type ], $hit ); } } // Merge back to $hits in the desired order $hits[0] = array_merge( $types['product'], $types['post'], $types['page'] ); return $hits; }
However, neither of them seem to work. The
relevanssi_hits_filter
returns an empty results page, even after rebuilding the index. Therelevanssi_comparison_order
just returns the results, ignoring the defined order.Any ideas? Help would be much appreciated!
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Ordering results by post type not working (with SF pro)’ is closed to new replies.