Title: custom query filter
Last modified: March 21, 2022

---

# custom query filter

 *  Resolved [xabdu](https://wordpress.org/support/users/xabdu/)
 * (@xabdu)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/custom-query-filter/)
 * Hi,
 * I want to add two sections using Elementor for the best-selling courses (courses
   that got a lot of purchases) and best rated (courses that got a high rating).
   each one has its own section (query), not together.
 * How can I make the custom query filter, and where do I add the custom query in
   which file?
 * Because I only have queries filter for last updated, date, comment, and ID.
 * I am using WordPress, Elementor, Tutor LMS, and WooCommerce.
 * I saw this: [https://developers.elementor.com/docs/hooks/custom-query-filter/](https://developers.elementor.com/docs/hooks/custom-query-filter/)
 * but I don’t know how to do it for the best-selling and best-rated and where I
   put the codes.
 * Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Elementor Team](https://wordpress.org/support/users/talmo/)
 * (@talmo)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/custom-query-filter/#post-15480800)
 * Hi,
 * As this is a code needed to be inserted into the free JS, I suggest opening a
   ticket with our developer’s forum where they can instruct you where to apply 
   the code and the following information needed –
    [https://github.com/elementor/elementor](https://github.com/elementor/elementor)
 * Also, please have a look at the following –
    [https://developer.wordpress.org/reference/classes/wp_query/](https://developer.wordpress.org/reference/classes/wp_query/)
 *  Thread Starter [xabdu](https://wordpress.org/support/users/xabdu/)
 * (@xabdu)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/custom-query-filter/#post-15481300)
 * I did that just now, but I see there are many unanswered requests. It has been
   a few months, and nobody answered their requests.
 * [https://github.com/elementor/elementor/discussions/18212](https://github.com/elementor/elementor/discussions/18212)
 *  [Elementor Team](https://wordpress.org/support/users/talmo/)
 * (@talmo)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/custom-query-filter/#post-15483210)
 * Hi,
 * Adding the code into elementor should be through the WP code.
 * Please have a look at the following guide to add it to your WP code –
    [https://www.wpbeginner.com/beginners-guide/beginners-guide-to-pasting-snippets-from-the-web-into-wordpress/](https://www.wpbeginner.com/beginners-guide/beginners-guide-to-pasting-snippets-from-the-web-into-wordpress/)
 *  Thread Starter [xabdu](https://wordpress.org/support/users/xabdu/)
 * (@xabdu)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/custom-query-filter/#post-15483975)
 * Thank you, but I need someone to help me to find the correct custom codes for
   the query filter.
 *  [Elementor Team](https://wordpress.org/support/users/talmo/)
 * (@talmo)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/custom-query-filter/#post-15509610)
 * Hi,
 * The issue, in this case, is that we will be handling the LMS content that may
   have different queries.
    For example, the popularity (‘orderby’ => ‘comment_count’)
   is based on number of comments. Since we do not know the LMS queries and how 
   it works, we can’t write the code for you. Also, we are not the developers, that
   is why I suggested going to our GitHub since it is run by the developers.
 * The code should look similiar to this:
 * function popularity_order_courses( $query ) {
    $query->set( ‘post_type’, ‘courses’);
   $query->set( ‘orderby’, ‘comment_count’ ); } add_action( ‘elementor/query/{$query_id}’,‘
   my_query_by_different_order’ );
 * add_action( ‘elementor/query/{$query_id}’, ‘popularity_order_courses’ );
 * But, since we do not know how exactly how you call your custom post types (courses),
   we can’t guarantee it will be 100% working.
    The code should be used inside the
   functions.php of the child theme or as a custom plugin.
 * I hope this gives you more insight into the process you need to go through.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘custom query filter’ is closed to new replies.

 * ![](https://ps.w.org/elementor/assets/icon-256x256.gif?rev=3444228)
 * [Elementor Website Builder - more than just a page builder](https://wordpress.org/plugins/elementor/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/elementor/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/elementor/)
 * [Active Topics](https://wordpress.org/support/plugin/elementor/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/elementor/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/elementor/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Elementor Team](https://wordpress.org/support/users/talmo/)
 * Last activity: [4 years, 2 months ago](https://wordpress.org/support/topic/custom-query-filter/#post-15509610)
 * Status: resolved