categories – Custom post type data not displaying If I select the category from the dropdonw

Question

I have created a custom post type. I am able to add all the details and it’s working.
I have a dropdown and I am getting my category in that dropdown. Once the user selects the category from the dropdown then data will display accoringly.

I tried the below code but I am not getting anything. Even error is also not showing.

function eventsView( $atts ){
    if($atts['cat']=='All'){            
        $upcomingevents = get_posts(array(
          'showposts' => 80, //add -1 if you want to show all posts
          'post_type' => 'events'
          ));
    }else{  
        $upcomingevents = get_posts(array(
          'showposts' => 10, //add -1 if you want to show all posts
          'post_type' => 'events',
          'tax_query' => array(
              array(
            'taxonomy' => 'events_cat',
            'field' => 'slug',
            'terms' => $atts['cat'] //pass your term name here
              )
            ))
           );
    }   
    echo"<pre>";
    print_r($upcomingevents); // Nothing is showing int his variable.

  // some more code here like foreach conditon
}

0
Naren Verma 2 years 2021-03-22T05:20:45-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse