toggle menu

ACF date fileds behalf of filltering data

Dhananjay Kumar |18 Apr at 01:04

Hello,

I have added start and end date in post type using advance custome fileds.

and want to view post list as per start & end date like  current events, past events and upcoming events..

I have do with below script :

if($_REQUEST['status']=="current"){
                $today = date('Ymd');
                $artposts = get_posts( array(
                'posts_per_page' => 30,
                'post_type'   => 'exhibitions',
                'meta_query' => array('relation' => 'OR',
                                      array('name'=> 'the_beginning_of_the_exhibition',
                                      'value'=> $today,
                                      'type' => 'DATE',
                                      'compare' => '<='),
                                      array('name'=> 'end_of_the_exhibition',
                                      'value'=> $today,
                                      'type' => 'DATE',
                                      'compare'    => '>=')
                                      ),
                'sort_order' => 'desc'
                ) );
               
            }else if($_REQUEST['status']=="past"){
                $artposts = get_posts( array(
                'posts_per_page' => 30,
                'post_type'   => 'exhibitions',
                'meta_query' => array(
                                     
                                      array('name'=> 'end_of_the_exhibition',
                                      'value'=> date('Ymd'),
                                      'type' => 'DATE',
                                      'compare'    => '<')
                                      ),
                'sort_order' => 'desc'
                ) );
               
            }else if($_REQUEST['status']=="upcoming"){
                $artposts = get_posts( array(
                'posts_per_page' => 30,
                'post_type'   => 'exhibitions',
                'meta_query' => array(
                                     
                                      array('name'=> 'the_beginning_of_the_exhibition',
                                      'value'=> date('Ymd'),
                                      'type' => 'DATE',
                                      'compare'    => '>')
                                      ),
                'sort_order' => 'desc'
                ) );
               
            }

 

Getting proper result with past and upcoming, but issues seems with current, any one have solution please suggest.

  • 2 likes
  • 0 comment

Posted:

18 Apr at 01:04

Viewed:

782 times

Active:

18 Apr at 01:04