Home › Forums › General Issues › A point on Date fields in WP_Query › Reply To: A point on Date fields in WP_Query
Hi Nox,
For your first question : the ‘NOT EXISTS’ operator means the metadata isn’t set or is set to null. So to understand why this operator doesn’t work in your case you can try this in the single_post.php (just to testing it):
if( ! in_array( 'date_sale', get_post_custom_keys( $post_id ) ) ) {
Echo ‘The metadata isn’t set, the NOT EXISTS operator must works’;
} else {
$my_sale_date_meta = get_post_meta($post_id, ‘date_sale’);
If(is_null($my_sale_date_meta)){
Echo ‘The metadata is null, the NOT EXISTS operator must works’;
} else {
Echo ‘The metadata is set and not null, the NOT EXISTS operator can\’t work’;
}
}
If you echo “… the NOT EXISTS operator must works” that’s means another part of your code make it wrong, else, it’s perfeclty normal it’s not working in your case because even if your field is empty the metadata is set and not null.
For your second issue, you have to process some testing too : Are you sure the metadata date_sale can be compared to you $date_limit ? Use the get_post_meta() to print your date_sale, but it’s possible that your date_sale return a string which can’t be compared to a DateTime. In that case you must convert your date_limit to a comparable format
Hope it’s help.
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.