-
AuthorPosts
-
September 14, 2022 at 6:02 pm #1365024
Hello
search results are displaying different results in the widget in the header top bar from those displayed in the normal search page, please see screenshot
What I would like to achieve is that products are displayed first, then posts and pages, especially in the header top bar widget
Is it possible?Thank you
MauroSeptember 15, 2022 at 7:51 am #1365072Hey profumopuntoit,
Thank you for the inquiry.
The following code using the posts_orderby filter should work but only for the default search results page. It is not going to affect the AJAX search. You can add it in the functions.php file.
function avf_order_search_by_posttype($orderby){ if (!is_admin() && is_search()) : global $wpdb; $orderby = " CASE WHEN {$wpdb->prefix}posts.post_type = 'product' THEN '1' WHEN {$wpdb->prefix}posts.post_type = 'portfolio' THEN '2' WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '3' ELSE {$wpdb->prefix}posts.post_type END ASC, {$wpdb->prefix}posts.post_title ASC"; endif; return $orderby; } add_filter('posts_orderby', 'avf_order_search_by_posttype');
Please make sure to purge the cache before testing.
Best regards,
IsmaelSeptember 15, 2022 at 11:20 am #1365104Thank you Ismael,
the code works great
but, as I said, my main concern is the display of product first results in the Ajax top bar widget, that is returning completely different results. Please see screenshot
Is it possible to change the ordering also there?September 16, 2022 at 10:25 am #1365226Hi,
Thank you for the update.
For the AJAX search, you have to directly modify the enfold/functions-enfold.php file, look for the avia_ajax_search function and this comment around line 410.
//now we got everything we need to preapre the output
Above this line, add this block.
$sorted = array('portfolio' => $sorted['portfolio']) + $sorted; $sorted = array('post' => $sorted['post']) + $sorted; $sorted = array('product' => $sorted['product']) + $sorted;
Best regards,
IsmaelSeptember 16, 2022 at 11:40 am #1365234Thank you Ismael,
but that means that any change made in the code will be lost in the next update. Will you please add this code in a future release?I think that all ecommerce Enfold clients will appreciate, because it is obvious that a shop owner will prefer that product will be displayed before anything else
Best regards,
Mauro- This reply was modified 2 years, 3 months ago by profumopuntoit.
September 18, 2022 at 2:38 pm #1365426September 19, 2022 at 10:38 am #1365505Thank you
Mauro
-
AuthorPosts
- You must be logged in to reply to this topic.