Sort by featured and rating

This topic contains 5 replies, has 3 voices, and was last updated by  Tania Perez 6 years, 7 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #394278

    Tania Perez
    Full Member
    Post count: 299

    Hi!

    I was looking at a way to sort the listings by “Featured” and then “Rating”, as you can choose either one of them.

    And came across a snippet you posted here:
    https://wpgeodirectory.com/support/topic/archive-display-sorting/
    where you can sort by Featured and then ABC, with the following shortcode:

    add_filter(‘geodir_posts_order_by_sort’,’_my_custom_order_by’,10,3);
    function _my_custom_order_by($orderby, $sort_by, $table){
    global $wpdb;

    if($sort_by==’is_featured_asc’){
    $orderby .= ” $wpdb->posts.post_title ASC, “;
    }
    return $orderby;
    }

    Is it possible to sort first featured and then rating instead of ABC?

    Thank you guys!

    #394349

    Kiran
    Moderator
    Post count: 7069

    Hi Tania,

    Use following code snippet to apply featured and then rating sorting.

    
    
    // Sorting the listing page results by featured & rating.
    function _gd_custom_sort_by_featured_and_rating( $orderby, $sort_by, $table ) {
        if ( $sort_by == 'is_featured_asc' && !empty( $table ) ) {
            $orderby .= " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, ";
        }
    
        return $orderby;
    }
    add_filter( 'geodir_posts_order_by_sort', '_gd_custom_sort_by_featured_and_rating', 5, 3 );

    Thanks,
    Kiran

    #394421

    Tania Perez
    Full Member
    Post count: 299

    Thank you Kiran!

    If I wanted to add tha ABC sorting, after the featured and rating, how can I do that?

    Thank you!!!!!!!

    #394423

    Paolo
    Site Admin
    Post count: 31206

    After sorting by featured and by rating, there is nothing left to sort…. what would you sort by ABC?

    Let us know,

    Thanks

    #394429

    Paolo
    Site Admin
    Post count: 31206

    If you mean sorting those who are not rated by ABC, it would make your site extremely slow…

    Thanks

    #394433

    Tania Perez
    Full Member
    Post count: 299

    OK thank you!

Viewing 6 posts - 1 through 6 (of 6 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket