Listify and FacetWP: How to order results by rating

David Nash wordpress 6 Comments

Listify is a WordPress directory listing theme. It allows users to submit listings (of businesses, for example) and also allows users to rate those listings. It uses the WP Job Manager plugin to manage the listings.

For some reason, it’s not currently possible to order the search results by user rating. The theme developers have told me that feature is planned for future releases.

If you purchase the FacetWP plugin, it becomes possible for the user to order the results, but rating is now included.

It took a little digging but here’s the solution, which I think is fairly elegant. Simply copy and paste this into the child theme’s functions.php:

//workaround bug in listify review system - allow users to submit more than one rating
add_filter( 'wpjmr_can_post_multiple_reviews', '__return_true' );

//sort by rating - need to store the new average rating in the post's custom field so FacetWP can access it
function custom_wpjmr_after_save_comment_review( $comment_id ) {

	$wpjmr = WP_Job_Manager_Reviews::instance(); //get global instance
	$wpjmr->review->save_rating_average_post_meta( $comment_id ); //use the built in function to save as meta on the listing post


add_action( 'wpjmr_after_save_comment_review', 'custom_wpjmr_after_save_comment_review' );

//order by rating - from
function my_facetwp_sort_options( $options, $params ) {

    $options['rating'] = array(
        'label' => 'Rating',
        'query_args' => array(
            'orderby' => 'meta_value_num', // sort by numerical custom field
            'meta_key' => '_average_rating', // required when sorting by custom fields
            'order' => 'DESC' // descending order
    return $options;

add_filter( 'facetwp_sort_options', 'my_facetwp_sort_options', 10, 2 );

How to get Listify and FacetWP to sort by rating: an explanation

Starting with FacetWP, I wanted to order the results by a custom field, as outlined here: .

The problem was that WP Job Manager stores the user ratings in wp_commentmeta. So either I could write code that looks at all comments on the post, gets the ratings, and calculates the average for each result. This would probably be too slow, especially if thousands of results were found.

My other idea was that every time a rating is submitted, I could update the average in the wp_postmeta table.

It turns out that WP Job Manager Reviews add-on already has a function that does this, but it’s not automatically called – it only seems to be used when comments are removed by the admin.

So I added an action that updates the average rating for a listing and saves it as a custom field.

Now I had something I could provide to FacetWP as a custom order by option, I tried it out and it’s all working well.

And that’s how you order by user rating with Listify and FacetWP.

I shared my code with the FacetWP author and he thought it was good enough to share with others, so I thought I would too!

I’ve done quite a bit of work recently with Listify, especially having trouble geocoding thousands of business addresses. If you have any questions, let me know, and I’ll try to write more posts about it.

Comments 6

  1. This looks really promising. I’m wondering though.

    With this approach can I automatically sort by rating?

    For example

    I’d like it to just list the highest rating listings first with non-rated listings being last. Do I need facetwp for this? I’m wondering if facetwp is going to be easier than just replacing the results code with my own in the file that lists the results. Since I don’t know wp shortcode this approach has helped me in other aspects of my site.

    Any advice is appreciated.

  2. Hi David,
    Awesome, I have another directory theme that I use, but also with FacetWP, I am not a developer so wondering if these steps and php code can be used exactly in other directory themes that use FacetWP? My directory theme comes with a not so good comments ratings and I would like to enable this filter at least! Thank you in advance!

  3. Hi. I have listify theme with WP Job Manager.
    I purchased FacetWP, but I cannot replicate the custom filters I had to custom facets in FacetWP.
    I don’t know how to tell FacetWP to use my WP Job manager custom filters.
    Any idea?

  4. Hey there!

    I’m Fernando, I work for the support department of Astoundify!

    Just wanted to let you know about our latest Listify update. We have improved the overall integration of the Facet WP plugin with our theme.

    New: Improved FacetWP integration includes:

    -Update FacetWP filter styles. Homepage facets now appear on a single line.
    -Results page now appear more visually appealing.
    -Support for new fSelect facet type.
    -Facet display can now easily be managed in “Customize > Listings > Facets”.
    -Display extra filters under a “More Filters” area.
    -Register default facets and templates for seamless activation.

    You can always ask us questions and we will be more than happy to answer them.
    Visit us here:

    Kind regards,


    1. Hi Maria,

      I’m Fernando, I work for the support department of Astoundify!

      You will be able to use the Facet WP plugin to add any new custom search filters on your homepage, including the Regions filter.

      Out of the box, you can use the Listing Region Search Filter as described here:

      If you require any assistance let us know over at our help desk or you can find a lot of helpful articles over at our docs section:

      Kind regards,


Leave a Reply