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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.