Title: Filter Missing When Adding Custom Meta Query
Last modified: October 6, 2022

---

# Filter Missing When Adding Custom Meta Query

 *  [roniewebstudio17](https://wordpress.org/support/users/roniewebstudio17/)
 * (@roniewebstudio17)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/filter-missing-when-adding-custom-meta-query/)
 * I have a product page with Product Filters active on the sidebar. I am trying
   to add a custom meta query in the functions.php but everytime I do, the Filters
   in the sidebar go missing. This is the query that I am setting:
 * $meta_query = $q->get( ‘meta_query’ );
    $meta_query[] = array( ‘key’ => ‘user_role_visibility’,‘
   compare’ => ‘LIKE’, ‘value’ => $user_role ); $q->set( ‘meta_query’, $meta_query);
 * Can you advise what may be the reason why the Filters are missing? Thanks!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Ffilter-missing-when-adding-custom-meta-query%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [Dmytro Holovnia](https://wordpress.org/support/users/dholovnia/)
 * (@dholovnia)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/filter-missing-when-adding-custom-meta-query/#post-16086337)
 * Hi,
 * Probably your query is influencing our filters query. You need to verify where
   you custom code is adding meta_query to.
 * You may want to use Query Monitor plugin to check where your meta_query is added
   to.
 * Regards,
    Dmytro
 *  Thread Starter [roniewebstudio17](https://wordpress.org/support/users/roniewebstudio17/)
 * (@roniewebstudio17)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/filter-missing-when-adding-custom-meta-query/#post-16264780)
 * Hi Dmytro,
 * Thanks for the reply. I was able to get the following query using Query Monitory
   plugin below:
 * SELECT COUNT( DISTINCT wp_1d01165959_posts.ID ) as term_count, MAX(term_relationships.
   term_taxonomy_id) as term_count_id
    FROM wp_1d01165959_posts INNER JOIN wp_1d01165959_postmeta
   AS mt1 ON ( wp_1d01165959_posts.ID = mt1.post_id ) INNER JOIN wp_1d01165959_term_relationships
   AS term_relationships ON wp_1d01165959_posts.ID = term_relationships.object_id
   WHERE wp_1d01165959_posts.post_type IN ( ‘product’ ) AND wp_1d01165959_posts.
   post_status = ‘publish’ AND ( wp_1d01165959_posts.ID NOT IN ( SELECT object_id
   FROM wp_1d01165959_term_relationships WHERE term_taxonomy_id IN (23) ) ) AND ((
   wp_1d01165959_postmeta.meta_key = ‘user_role_visibility’ AND wp_1d01165959_postmeta.
   meta_value LIKE ‘%Customer%’ ) AND ( mt1.meta_key = ‘user_role_visibility’ AND
   mt1.meta_value LIKE ‘%Customer%’ ) ) AND term_relationships.term_taxonomy_id 
   IN (244,242,264,266,245,243,247,246,265) GROUP BY term_relationships.term_taxonomy_id
 * There is an error:
 * Unknown column ‘wp_1d01165959_postmeta.meta_key’ in ‘where clause’
 * There is a duplicate condition where one condition is using an alias (mt1) and
   another condition is accessing the column directly wp_1d01165959_postmeta.meta_key.
 * Do you know how can this be rectified? Thanks!
 *  Plugin Author [Dmytro Holovnia](https://wordpress.org/support/users/dholovnia/)
 * (@dholovnia)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/filter-missing-when-adding-custom-meta-query/#post-16268746)
 * Hi,
 * You need to have own postmeta entity with
 *     ```
       INNER JOIN wp_1d01165959_postmeta AS pm_my
       ON ( wp_1d01165959_posts.ID = pm_my.post_id )
       ```
   
 * and
 *     ```
       AND ( ( pm_my.meta_key = 'user_role_visibility'
       AND pm_my.meta_value LIKE '%Customer%' )
       ```
   
 * This way it will be working.
 * Or at least add it to the FROM. You have selection from tables ‘posts’, ‘postmeta
   AS mt1’ and ‘term_relationships AS term_relationships’. You are trying to get
   values from the table postmeta while it is not in the list. postmeta in the request
   is attached as an mt1.
 * Regards,
    Dmytro

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

The topic ‘Filter Missing When Adding Custom Meta Query’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-ajax-filters/assets/icon-256x256.gif?rev=2770304)
 * [Advanced AJAX Product Filters](https://wordpress.org/plugins/woocommerce-ajax-filters/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-ajax-filters/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-ajax-filters/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-ajax-filters/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-ajax-filters/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-ajax-filters/reviews/)

## Tags

 * [custom-query](https://wordpress.org/support/topic-tag/custom-query/)

 * 3 replies
 * 2 participants
 * Last reply from: [Dmytro Holovnia](https://wordpress.org/support/users/dholovnia/)
 * Last activity: [3 years, 6 months ago](https://wordpress.org/support/topic/filter-missing-when-adding-custom-meta-query/#post-16268746)
 * Status: not resolved