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
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!
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