I have archive-events.php file that sorts custom post type ‘events’ via WP_Query using custom field that is date formatted YYYYMMDD (20150215) like this:

$args = array(
    'post_type'     => 'events',
    'posts_per_page'=> 10,
    'meta_key'      => 'wpcf-sort-events',
    'orderby'       => 'meta_value_num',
    'order'         => 'ASC'
);
$wp_query = new WP_Query( $args );

Then I made a widget that displays custom calendar with date links to compare custom field dates via add_query_arg and display events archived from that date onwards like this:

$day = I get the day for the calendar before this... 01
$date = I get the full date (Ymd 20150501) from calendar widget to compare
$arrayargs = array(
    'meta_query' => array(
         'key'        => 'wpcf-sort-events',
         'value'      => $date,
         'compare'    => '>='
         ),
     );                                                                                                                                                         
$output = '<a href="' . add_query_arg( $arrayargs ) . '>' . $day . '</a> ';

This creates a link like this:
http://mediterranean.life/events/?meta_query%5Bkey%5D=wpcf-sort-events&meta_query%5Bvalue%5D=20150501&meta_query%5Bcompare%5D=%3E

But I get all events (no matter the custom date) sorted ASC like query in archive-events.php, it ignores meta_query via link…

I have tried creating a link with a full query like this, but also failed…

$arrayargs = array(
            'post_type' => 'events',
            'meta_key' => 'wpcf-sort-events',
            'meta_query' => array(
                'key' => 'wpcf-sort-events',
                'value' => $date,
                'compare' => '>='
                ),
            'orderby' => 'meta_value_num',
            'order' => 'ASC'
        );                                                                                                                                                          
        $output = '<a href="' . add_query_arg( $arrayargs ). '>' . $day . '</a> ';

Lost in space… any ideas?

Read more here: add_query_arg to compare and display events from a certain date


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: