0

I'm trying to fetch all the posts from today to next week by using some custom fields inside posts, using Advanced Custom Fields.

Everything was working until now, because it doesn't show posts from the next month. For example:

I've got posts whose 'date' custom field is '28/01/2015' or '29/01/2015' or '30/01/2015' and everything is working.

But I've got some posts which 'date' is '01/02/2015' and '02/02/2015' and they're not showing at all.

In ACF I've set the 'date' custom field as a jQuery Datepicker, which show dates in dd/mm/yy format and save them also as dd/mm/yy.

This is my code:

                $t=date('d/m/Y',strtotime('+7 day'));
                $o=date('d/m/Y',strtotime('today'));

                $d=new WP_Query(
                    array(
                        'category__in' => array(4),
                        'post_type' => 'post',
                        'posts_per_page' => '-1',
                        'orderby' => 'meta_value',
                        'order' => 'ASC',
                        'meta_query' => array(
                            'relation' => 'AND'
                            array(
                                'key' => 'data',
                                'value' => $o,
                                'compare' => '>='
                            ),
                            array(
                                'key' => 'data',
                                'value' => $t,
                                'compare' => '<'
                            )
                        )
                    )
                );

Can someone help? Thanks in advice.

  • You are going to have a tough time doing this. Your date format is wrong. It should be YYYY-MM-DD. – Pieter Goosen Jan 28 '15 at 14:59
  • So are you saying that the only problem is the date format inside database? Is everything fine inside the code? – CapitanFindus Jan 28 '15 at 15:04
  • On eye value, it looks fine. – Pieter Goosen Jan 28 '15 at 15:05
  • Ok, better than expected, if the only problem is date format, it's not an enormous problem by the way – CapitanFindus Jan 28 '15 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.