I have archive-events.php file that sorts custom post type ‘events’ via WP_Query using custom field that is date formatted Ymd (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 widget that displays custom calendar with date links to compare custom field date via add_query_arg and display events archive from that date on 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 link like this:

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

Tried creating link with 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 certain date


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: