$cats = get_the_category($post->ID); $args = array( 'post_type' => 'event', 'post__not_in' => array( get_the_ID() ), 'posts_per_page' => 5, 'cat' => $cats[0]->term_id, 'meta_query' => array( array( //'key' => 'recommended_article', 'value' => '1', 'compare' => '==' ) ) ); //debut loop---------------------- $event_query = new WP_Query( $args ); if ( $event_query->have_posts() ) { echo '<div><h2 style="font-weight: 600 !important;text-decoration: underline;margin-bottom: 10px;font-size: 18px !important;">Autre(s) date(s) sur le même thème</h2></div>'; echo '<ul style="list-style: none outside;">'; while ( $event_query->have_posts() ) { $event_query->the_post(); //if( $event_query->have_posts() ) : while( $event_query->have_posts() ) : $event_query->the_post(); global $post, $wp_rewrite; $EM_Event = em_get_event($post); $postcat = wp_get_post_terms($post->ID, 'category'); //class $type = get_post_type(array('sf','essaimer')); $category = get_the_category(); $category_parent_id = $category[0]->category_parent; if ( $category_parent_id != 0 ) { $category_parent = get_term( $category_parent_id, 'category' ); $css_slug = $category_parent->slug; } else { $css_slug = $category[0]->slug; } echo $EM_Event->output('<li class="'.esc_html( $postcat[0]->slug ).'" > -> le <b>#_EVENTDATES</b> <a href="'. site_url() .'/'.$category_parent->slug .'/'.$type->slug.'">#_EVENTNAME</a> à <b>#_LOCATIONTOWN</b></li>'); }}/*endwhile; endif;*/ wp_reset_postdata();