New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with query by date field not return proper post after date is updated #1815

Open
Shelob9 opened this Issue Oct 26, 2013 · 2 comments

Comments

Projects
None yet
3 participants
@Shelob9
Contributor

Shelob9 commented Oct 26, 2013

In this support forum thread user reports an issue with ordering by a date field. I have confirmed the issue he is describing.

With this code:

$todays_date = get_the_date();
$params = array(
        'limit' => 1,
    'where' => 'DATE( event_date.meta_value ) >= "' . $todays_date . '"'
);
$pod = pods('event', $params);

The post with the date closest to current date in the date field 'event_date' is return, as expected but if the post with the closest date in its date field is change so it is no longer the closest date, it is still returned.

Oddly enough, the issue is resolved by adding an orderby clause 'orderby' => 'event_date.meta_value',, which shouldn't be needed.

Issue is present in 2.3.12 but was not in previous versions. User is unsure which version the issue was last not present for.

@ghost ghost assigned sc0ttkclark Oct 29, 2013

@sc0ttkclark sc0ttkclark removed their assignment May 26, 2014

@sc0ttkclark sc0ttkclark modified the milestones: Pods 3.1, Pods 3.0 Jun 4, 2014

@Shelob9

This comment has been minimized.

Show comment
Hide comment
@Shelob9

Shelob9 Oct 9, 2014

Contributor

Someone searching this, might like this alternate syntax that seems to work for me, both in a find() params and in a short code:

[pods name="event" where="DATE( event_date.meta_value ) >= NOW()" orderby="event_date.meta_value"]{@post_title}[/pods]

    $params = array(
        'limit' => 4,
        // the following orderby is required to preserve event date order (until the bug is fixed)
        'orderby' => 'event_date.meta_value',
        'where' => 'DATE( event_date.meta_value ) >= NOW()'
    );
    $pods = pods( 'event', $params );
Contributor

Shelob9 commented Oct 9, 2014

Someone searching this, might like this alternate syntax that seems to work for me, both in a find() params and in a short code:

[pods name="event" where="DATE( event_date.meta_value ) >= NOW()" orderby="event_date.meta_value"]{@post_title}[/pods]

    $params = array(
        'limit' => 4,
        // the following orderby is required to preserve event date order (until the bug is fixed)
        'orderby' => 'event_date.meta_value',
        'where' => 'DATE( event_date.meta_value ) >= NOW()'
    );
    $pods = pods( 'event', $params );
@christoferw

This comment has been minimized.

Show comment
Hide comment
@christoferw

christoferw Feb 26, 2016

I have also have problems sorting and filtering events, here is what i need to do / tried to do:
`
// german date format: 31.12.2016 - >day.month.year
$ctw_today = date('d.m.Y');
$my_meta_query = array(
'relation' => 'OR',
array(
'key' => 'anfangsdatum', //start date of the event
'compare' => '>=',
'value' => $ctw_today,
),
array(
'key' => 'enddatum', //end date of the event
'compare' => '>=',
'value' => $ctw_today,
)
);

$query_args = array(
'post_type' => 'event',
'post_status' => 'publish',
'posts_per_page' => 50,
'meta_key' => 'anfangsdatum', // anfangsdatum
'meta_type' => 'DATE',
'meta_query' => $my_meta_query,
'order' => 'ASC',
'orderby' => 'meta_value meta_value_num', //sortiere nach einem meta-feld
);
query_posts($query_args);
`
I am not sure how to use your workaround in my case. can you help me with that?

I have also have problems sorting and filtering events, here is what i need to do / tried to do:
`
// german date format: 31.12.2016 - >day.month.year
$ctw_today = date('d.m.Y');
$my_meta_query = array(
'relation' => 'OR',
array(
'key' => 'anfangsdatum', //start date of the event
'compare' => '>=',
'value' => $ctw_today,
),
array(
'key' => 'enddatum', //end date of the event
'compare' => '>=',
'value' => $ctw_today,
)
);

$query_args = array(
'post_type' => 'event',
'post_status' => 'publish',
'posts_per_page' => 50,
'meta_key' => 'anfangsdatum', // anfangsdatum
'meta_type' => 'DATE',
'meta_query' => $my_meta_query,
'order' => 'ASC',
'orderby' => 'meta_value meta_value_num', //sortiere nach einem meta-feld
);
query_posts($query_args);
`
I am not sure how to use your workaround in my case. can you help me with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment