Title: custom query not filtering
Last modified: September 6, 2024

---

# custom query not filtering

 *  Resolved [beau321](https://wordpress.org/support/users/beau321/)
 * (@beau321)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-query-not-filtering/)
 * i use elementor form to create a custom search form and a custom query code to
   point to a post widget used in a elementor search result template. The post widget
   has query id the reason why it was used. I also use elementor custom skins pro
   to customize how the product should show in results. after applying the code:
   the results show up empty. before correcting the parameters and query id, it 
   wasn’t filtering between the two products i’ve created. the default elementor
   form work great filtering the product, but the custom form, idk. Please take 
   a look and help me please. Here is the custom query code:
 * add_action(‘elementor/query/my_custom_filter’, function ($query) {
 *     ```wp-block-code
       $meta_query = array('relation' => 'AND');
   
       // Check if CAS Number is provided, using '=' comparison
       if (!empty($_GET['cas_number'])) {
           $meta_query[] = array(
               'key' => 'CAS Number',  // Correct key name without underscore
               'value' => sanitize_text_field($_GET['cas_number']),
               'compare' => '='  // Exact match
           );
       }
   
       // Check if Supplier is provided, using LIKE comparison
       if (!empty($_GET['supplier'])) {
           $meta_query[] = array(
               'key' => 'Supplier',  // Correct key name for supplier
               'value' => sanitize_text_field($_GET['supplier']),
               'compare' => 'LIKE'  // Partial match
           );
       }
   
       // Check if Other Search Term is provided, using '=' comparison
       if (!empty($_GET['other_search_term'])) {
           $meta_query[] = array(
               'key' => 'Other Search Term',  // Correct key name without underscore
               'value' => sanitize_text_field($_GET['other_search_term']),
               'compare' => '='  // Exact match
           );
       }
   
       // Check if Estimated Delivery Time is provided, using LIKE comparison
       if (!empty($_GET['estimated_delivery_time'])) {
           $meta_query[] = array(
               'key' => 'Estimated Delivery Time',  // Correct key name for delivery time
               'value' => sanitize_text_field($_GET['estimated_delivery_time']),
               'compare' => 'LIKE'  // Partial match
           );
       }
   
       // Check if Minimum Price and Maximum Price are provided, using BETWEEN comparison
       if (!empty($_GET['min_price']) && !empty($_GET['max_price'])) {
           $meta_query[] = array(
               'key' => 'Price',  // WooCommerce standard price field
               'value' => array(sanitize_text_field($_GET['min_price']), sanitize_text_field($_GET['max_price'])),
               'type' => 'NUMERIC',
               'compare' => 'BETWEEN'
           );
       }
   
       // Only apply the meta query if it's not empty
       if (!empty($meta_query)) {
           $query->set('meta_query', $meta_query);
       }
       ```
   
 * });
 * this is the redirect url: [https://nordchem.se/?elementor_library=search-results&cas_number=%5Bfield id=”cas_number”]&supplier=[field id=”supplier”]&other_search_term=[field id=”other_search_term”]&estimated_delivery_time=[field id=”estimated_delivery_time”]&min_price=[field id=”min_price”]&max_price=[field id=”max_price”]](https://nordchem.se/?elementor_library=search-results&cas_number=[field id="cas_number"]&supplier=[field id="supplier"]&other_search_term=[field id="other_search_term"]&estimated_delivery_time=[field id="estimated_delivery_time"]&min_price=[field id="min_price"]&max_price=[field id="max_price"])
 * the only other custom code i have is to hide and reveal the hidden container 
   of a product to reveal details of the product which works sometimes idk why. 
   here is the code:
 * document.addEventListener(‘DOMContentLoaded’, function() {
   // Get all the buttons
   and chemical detail containersconst detailsBtns = document.querySelectorAll(‘.
   details-btn’);const chemicalDetailsContainers = document.querySelectorAll(‘.chemical-
   details’);
 *     ```wp-block-code
       // Hide all chemical details containers by default
       chemicalDetailsContainers.forEach(function(container) {
           container.style.display = 'none';
       });
   
       // Attach click event to each button
       detailsBtns.forEach(function(btn, index) {
           btn.addEventListener('click', function() {
               const chemicalDetails = chemicalDetailsContainers[index];
               if (chemicalDetails.style.display === 'none') {
                   chemicalDetails.style.display = 'block';
               } else {
                   chemicalDetails.style.display = 'none';
               }
           });
       });
       ```
   
 * });
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcustom-query-not-filtering%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  [Jamie Marsland](https://wordpress.org/support/users/jamesmarsland/)
 * (@jamesmarsland)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-query-not-filtering/#post-17999144)
 * Hi, as this is specific to Elementor , could you post in their dedicated support
   forum please [https://wordpress.org/support/plugin/elementor/](https://wordpress.org/support/plugin/elementor/)
 *  Moderator [Support Moderator](https://wordpress.org/support/users/moderator/)
 * (@moderator)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/custom-query-not-filtering/#post-18000214)
 * Thread continues at [https://wordpress.org/support/topic/custom-query-not-filtering-2/](https://wordpress.org/support/topic/custom-query-not-filtering-2/)

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

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

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 2 participants
 * Last reply from: [Support Moderator](https://wordpress.org/support/users/moderator/)
 * Last activity: [1 year, 7 months ago](https://wordpress.org/support/topic/custom-query-not-filtering/#post-18000214)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
