@jarvis Thanks for that. Did add the option to choose number of posts as well so adjusted the code and am now using:
/ Variables $number_of_events = get_field( 'number_of_events' ); // print_r($number_of_events); $event_categories = get_field('event_categories'); $event_cat_ids = wp_list_pluck( $event_categories, 'term_id' ); #$event_cat_ids = array( 1, 31 ); $args = array( 'post_type' => 'event', 'post_status' => 'publish', 'posts_per_page' => $number_of_events, 'order' => 'DESC', ); $args['tax_query'] = array( 'relation' => 'OR', array( 'taxonomy' => 'event_category', 'field' => 'term_id', 'terms' => $event_cat_ids ), ); $query = new WP_Query( $args ); if( $query->have_posts() ) : while( $query->have_posts() ): $query->the_post(); ?> <?php the_title(); ?> <?php endwhile; wp_reset_postdata(); endif; ?>
I see two times the one and only post for event category local.
This when I choose 1 event and category local. So somehow things repeat themselves. Two, I see a warning
Warning: foreach() argument must be of type array|object, null given in /Users/jasper/code/site/wp-includes/class-wp-list-util.php on line 164
and when I print
print_r($event_cat_ids); I see
Array (  => 180 ) Event Two Local Array (  => 180 ) Event Two Local
so closer, but not quite.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
2022 was a big year for Advanced Custom Fields, with more capabilities, a new generation of ACF Blocks, a refreshed UI, and a new home. Our year in review post looks at advancements we’ve made and offers a glimpse of the future.— Advanced Custom Fields (@wp_acf) January 6, 2023
© 2023 Advanced Custom Fields.