Jump to content

rhand

New Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by rhand

  1. This question might be too WordPress specific after all. So will ask at another forum focussed on WordPress and ACF.
  2. Been stuck for a while trying to simply feed event ACF multi select category choices into a WP Query to only load custom post types with those categories frontend. The issue I am having is a PHP issue as I do not seem to be able to convert data to data that the WP Query can handle. Been using // Variables $number_of_events = get_field( 'number_of_events' ); // print_r($number_of_events); $event_object = get_field_object('events_category'); // print_r($event_object); $event_cat_name = $event_object['value']; print_r($event_cat_name); $event_cat_slug = $event_cat_name[0]->slug; // print_r($event_cat_slug); $args = array( 'post_type' => 'event', 'posts_per_page' => $number_of_events, 'event_category' => $event_cat_slug ); $the_query = new WP_Query( $args ); ?> But the issue is now that $events_cat_slug only loads the first category chosen in ACF multi select. So I was considering using $args = array( 'post_type' => 'event', 'posts_per_page' => $number_of_events, 'tax_query' => array( array( 'taxonomy' => 'event_category', 'terms' => $cat_names ) ) ); So I can add an array of terms to terms.. like `'terms' => array(cat1, cat2,)` I do get Array ( [0] => WP_Term Object ( [term_id] => 180 [name] => OnSite [slug] => onsite [term_group] => 0 [term_taxonomy_id] => 180 [taxonomy] => event_category [description] => [parent] => 0 [count] => 1 [filter] => raw [meta] => Array ( ) ) [1] => WP_Term Object ( [term_id] => 179 [name] => Virtual [slug] => virtual [term_group] => 0 [term_taxonomy_id] => 179 [taxonomy] => event_category [description] => [parent] => 0 [count] => 3 [filter] => raw [meta] => Array ( ) ) ) for current `print_r($event_cat_name);`. But how can I get all the slugs from array key 0 and array key 1 and in a way I can feed that to terms? Been trying `array_columns`: `$cat_names = array_column($event_cat_name, 'slug');` but it still prints `Array ( [0] => onsite )` with one category for example and terms chokes on it. How can I use the slug values from the arrays in `$event_cat_name` in a way terms can load it?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.