Home › Forums › General Issues › Meta query for image field issue › Reply To: Meta query for image field issue
When you remove the image and update the post acf sets the db value to ” and empty string. There does not seem to be any reason why the query you had should not work other than something in WP. It seems that by putting in the ‘EXISTS’ part that WP does not use the second part with an empty value. There is an answer before that one that covers altering the WHERE part of the query.
function yoursite_posts_where($where,$query) {
global $wpdb;
$new_where = " TRIM(IFNULL({$wpdb->postmeta}.meta_value,''))<>'' ";
if (empty($where))
$where = $new_where;
else
$where = "{$where} AND {$new_where}";
return $where;
}
add_filter('posts_where','yoursite_posts_where',10,2);
$wp_query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_key' => 'delight_image',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'delight_image',
'compare' => 'EXISTS',
),
array(
'key' => 'delight_image',
'value' => '',
'compare' => '!=',
),
),
) );
remove_filter('posts_where','yoursite_posts_where',10,2);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We demoed ACF 6.1 Beta during the most recent session of ACF Chat Fridays, highlighting the new ability to regenerate and clear labels, setting the Admin Menu Parent as a slug, and more. Catch the video replay in our latest summary. https://t.co/rHEpPVas64 pic.twitter.com/hB1XKTexXi
— Advanced Custom Fields (@wp_acf) March 23, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.