Support

Account

Home Forums General Issues Custom year dropdown filter for CPT Reply To: Custom year dropdown filter for CPT

  • Hi @kaolarsan,

    Thanks for the post.

    The easiest way to go about this would be to create a custom query using the get_posts() function and filter the posts using the values entered in the datepicker field.

    Essentially, the code would look like so:

    <?php 
    
    $today = date('Ymd');
    
    $args = array (
        'post_type' => 'post',
        'meta_query' => array(
    		array(
    	        'key'		=> 'start_date',
    	        'compare'	=> '>=',
    	        'value'		=> $today,
    	    ),
    	     array(
    	        'key'		=> 'end_date',
    	        'compare'	=> '<=',
    	        'value'		=> $today,
    	    )
        ),
    );
    
    // get posts
    $posts = get_posts($args);
    ?>