0

Hi I am trying to query a custom post by an advanced custom field that is a date field and this is how it is registered in a plugin that I have created to take care of all non-visual aspects of the site:

fields' => array (
array (
    'key' => 'field_528eb92c26db4',
    'label' => __('Tip of the day date'),
    'name' => 'tip_of_the_day_date',
    'type' => 'date_picker',
    'date_format' => 'yymmdd',
    'display_format' => 'dd/mm/yy',
    'first_day' => 1,
),
),

Now I have a WP_query in a page that is supposed to display the "tip of the day" and this is supposed to be showing the tips that have this date field as today's date. This query looks like this:

$today = date('Ymd', strtotime("now"));
    $args = array(                              
    'orderby' => 'post_date',                                                           
    'post_type'        => 'bounty_tip',
    'post_status'      => 'any',
    'posts_per_page' => -1,
    'meta_query' => array(
        array(
            'key' => 'tip_of_the_day_date',
            'value' => $today,
            'compare' => '=',
            'type' => 'DATE'
        )
    )

);

Now the issue is that this works but ONLY if there are two posts that have the date. It stops working if there is only one... It is quite unusual and I am pulling my hair out trying to fix this.

Does anyone have any ideas why on earth this would happen? I just can't understand how it could work to pick up two (so clearly the meta_query is fine) but not just the one.

Thanks in advance I need to finish this to get sign off and this is my last resort!

Cheers

6
  • Please confirm that the 'date_format' => 'yymmdd' you are saving data and $today = date('Ymd', strtotime("now")) have the same format.
    – sri
    Feb 20, 2014 at 10:26
  • Yes when I var_dump my $today variable I get string(8) "20140220". Regardless why would that make it show up two but not one? If the date format were different wouldn't one expect none to ever show up regardless of the number?
    – sethreidnz
    Feb 20, 2014 at 10:34
  • You are right, but there could be something else that is also playing up!!
    – sri
    Feb 20, 2014 at 10:35
  • I know this is very frustrating as it's one of those problems where I honestly don't know what step to take next to trouble shoot it.
    – sethreidnz
    Feb 20, 2014 at 10:38
  • Can you also provide the code for how you save tip_of_the_day_date
    – sri
    Feb 20, 2014 at 10:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.