• Resolved stoi2m1

    (@stoi2m1)


    I would like to query the results for posts that have two meta_keys of start_date and finish_date.

    I would like to compare these dates for results of upcoming, current and past posts. I can use the WP_Query() class to get the upcoming and past results, but can I use if to get the current posts results, or will I need to use the $wpdb object to get those results?

    Im using the following comparisons to get my results
    if upcoming – start_date < today
    if current – start_date > today && finish_date < today
    if past – finish_date > today

    Thanks,
    Jesse

Viewing 1 replies (of 1 total)
  • Thread Starter stoi2m1

    (@stoi2m1)

    I managed to figure this out on my own.
    This is an example for if current. comparing two different meta_keys and their values.

    $args['meta_query'] = array(
    'relation' => 'AND',
    array(
    'key' => 'start_date',
    'value' => strtotime("now"),
    'compare' => '<'
    ),
    array(
    'key' => 'end_date',
    'value' => strtotime("now"),
    'compare' => '>'
    )
    );
    $results = new WP_Query($args);

    I hope this helps someone else in the future

Viewing 1 replies (of 1 total)
  • The topic ‘Query and Compare Two meta_values from Two Different meta_keys’ is closed to new replies.