Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #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
    Mauro

    #1365072

    Hey 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,
    Ismael

    #1365104

    Thank 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?

    #1365226

    Hi,

    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,
    Ismael

    #1365234

    Thank 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

    #1365426

    Hi,
    I have submitted this request to the Dev Team for review.

    Best regards,
    Mike

    #1365505

    Thank you

    Mauro

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.