Category sort in Bestof widget

This topic contains 14 replies, has 4 voices, and was last updated by  Giri 7 years, 4 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #336904

    Mitch Canton
    Expired Member
    Post count: 167

    I still don’t understand the sorting of the categories on the left side of the Bestof widget. I can’t make any sense of how it’s done.

    I have a new install, no reviews in place.

    And the sort is like:

    Insurance – 3 items
    Medical – 3 items
    House and Home – 4 items
    Florists – 1 item
    Food – 20 items (which is # set as max in widget)
    Moving and Storage – 1 item
    Real Estate – 6 items

    and so on for 30 or so cats.

    They are obviously not by Alpha (which is what I would like).
    They are not by most reviewed (as we have 0 reviews).
    They are not by number of listings in each category.

    I would like the ability to choose the sorting of the category names in this widget.

    I have created a WPGD custom plugin for various code I have added. Is there something code wise I could add to get this to make any sense?

    Thank you.

    #337305

    Kor
    Moderator
    Post count: 16516

    Hi Mitch,

    Like we’ve mentioned on the previous thread https://wpgeodirectory.com/support/topic/sort-of-categories-in-widget/ sort order that cannot be changed without a customization.

    Thanks!

    #337570

    Mitch Canton
    Expired Member
    Post count: 167

    Yes, I remember that discussion, but I felt it unresolved.

    As I mentioned, I have ZERO reviews in any of the 30 categories. So it CAN’T be sorting by number of reviews. There MUST be some secondary sort mechanism, since ALL of the categories have the same number of reviews.

    I’m simply looking for how to change that sort order, even if I need to try and tweak the code to do so.

    Can you not provide any assistance on what I should look to do?

    Thank you.

    #337575

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    I asked to the developer who wrote that widget to try and point you in the right direction, however when there are no options to do something (best of only sort by ratings) and you desire to change how it works, that is considered a customization and customization are beyond support.

    Thanks

    #337634

    Mitch Canton
    Expired Member
    Post count: 167

    I understand. However, you say ‘best of only sort by ratings’ – when there are ZERO ratings and ANY of the categories, it HAS to be sorting the display of categories by something??

    And if it is sorting by something, there has to be a way to modify that.

    It seems like just making some simple tweaks to someplace like line 183:

    $terms = geodir_sort_terms($a_terms, 'review_count');

    or 190:

    'order_by' => 'high_review'

    or 312:

    $view_all_link = add_query_arg(array('sort_by' => 'rating_count_desc'), get_term_link($first_term, $first_term->taxonomy));

    or 661:

    $view_all_link = add_query_arg(array('sort_by' => 'rating_count_desc'), get_term_link($term));

    to change like review_count in line 183 to be something alpha related would work?

    If I’m willing to go in and make the changes, simply providing me with the term I need for an ‘alpha’ sort and confirming the location doesn’t seem like it would be too much to ask.

    Thank you.

    #337896

    Giri
    Expired Member
    Post count: 3155
    $terms = geodir_sort_terms($a_terms, 'review_count');

    Categories / Terms are ordered by review count. We store review count in each category. So if some category review count looks wrong, its better to submit a new review in any one of the listing in that particular category. That would resave the review count.

    
    
    
    'order_by' => 'high_review'

    That part is for the listings in a particular category. Listings are ordered by high reviews in this case.

    $view_all_link

    This is just a link that points to the individual category page.

    If there is a bug its better to give us your credentials. We are happy to fix it.

    Thanks

    #338080

    Mitch Canton
    Expired Member
    Post count: 167

    Thanks, I’m not saying it’s a ‘bug’ per se. I just think it’s a flaw in the design to not allow for sorting of the category labels in the widget.

    So would I be able to replace ‘review_count’ in the widget code with something related to an “alpha sort of the category” (obviously not the right term) 🙂 to derive a revised sort of those category labels?

    Thank you for your follow-up. Have a good day.

    #338083

    Giri
    Expired Member
    Post count: 3155

    Hi Mitch,

    You seems like you have been trying long time. So let me help you.

    I have added two filters just now in best of widget for you. It will be included in next version. But in the mean time please follow my steps.

    Step 1)

    Modify the code in your site. See this page for the code I modified.

    https://gist.github.com/mistergiri/17437731f7027314d7ca144fed117a8e/revisions

    Step 2)

    Since you are planning to sort category by alphabetical order you need to use the following filter.

    bestof_widget_term_args

    Just place the following code in your child theme’s functions.php file.

    
    
    add_filter('bestof_widget_term_args', 'custom_bestof_widget_term_args');
    function custom_bestof_widget_term_args($term_args) {
    
        $term_args['orderby'] = 'name';
        $term_args['order'] = 'ASC';
    
        return $term_args;
    }

    Now we need to remove the review_count sort.

    So we need to use

    bestof_widget_sort_terms

    filter.

    Just place the following code too in your child theme’s functions.php file.

    
    
    add_filter('bestof_widget_sort_terms', 'custom_bestof_widget_sort_terms', 10, 2);
    function custom_bestof_widget_sort_terms($terms, $a_terms) {
        return $a_terms;
    }

    I have not tested it. But let me know if you face any problem. I’ll be here for another 30 mins. If you can try my code and face any problem I can help you before I leave. Otherwise i’ll help you on monday.

    Thanks

    #338088

    Mitch Canton
    Expired Member
    Post count: 167

    I tested this quickly so I could reply before you left.

    It works perfectly. 🙂 The category order displayed in the widget is alpha A-Z, and of course works in all configurations (top, side, dropdown).

    When I was originally testing WPGD, in reviewing the forums, this is the type of support that led me to the decision to purchase an annual subscription to the full plugin program.

    You are awesome, thanks.

    One quick question: Can I assume that if I leave out the second filter, the sort *within* the category (the company listings themselves) will still be based on the number of reviews?

    Have a fantastic weekend.

    #338118

    Giri
    Expired Member
    Post count: 3155

    I’m glad it worked.

    One quick question: Can I assume that if I leave out the second filter, the sort *within* the category (the company listings themselves) will still be based on the number of reviews?

    You need to use both filters in order to category sort work.

    The first filter (bestof_widget_term_args) makes sure the category is ordered A-Z and the second filter (bestof_widget_sort_terms) overrides our review_count sort function.

    So you need both filters in order category sort work.

    I have not modified anything inside the category listings sort. So it works as usual. Listings are sorted by high reviews.

    Hope that helps.

    Thanks

    #338122

    Mitch Canton
    Expired Member
    Post count: 167

    Got it. I noticed after placing the code that the Listings were also sorted alpha A-Z within each category, but since ALL of the listings currently have 0 reviews, that’s likely why.

    I’ll add some reviews to test.

    Excellent support. Thanks again. Enjoy your weekend!

    #338156

    Giri
    Expired Member
    Post count: 3155

    No problem Mitch.

    If you find any bugs, please report it here.

    I’ll fix those bugs on monday.

    Have a great weekend 🙂

    #338157

    Giri
    Expired Member
    Post count: 3155

    Hi Mitch,

    Sorry to trouble you.

    If you have not left a review yet for our plugin, please spend couple of minutes and leave a review here.

    https://wordpress.org/support/plugin/geodirectory/reviews/#new-post

    This would help us grow.

    Thanks

    #339372

    Mitch Canton
    Expired Member
    Post count: 167

    Not a trouble at all. I’ll put something together for a review. I appreciate the support you have provided.

    Have a great day.

    #339416

    Giri
    Expired Member
    Post count: 3155

    Thanks Mitch.

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

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

Open Support Ticket