Home › Forums › General Issues › Help in using Taxonomy Field Type › Reply To: Help in using Taxonomy Field Type
To load the selected values from a taxonomy field, you can use the get_field function like so:
$selected = get_field('taxonomy_field_name');
I just looked at the get_posts documentation and the following is very useful:
Note: The category parameter needs to be the ID of the category, and not the category name. Note: The category parameter can be a comma separated list of categories, as the get_posts() function passes the 'category' parameter directly into WP_Query as 'cat'.
So, with that in mind, please edit your taxonomy field and select ‘ID’ as the return format setting. Then you can use the following code:
$selected = get_field('taxonomy_field_name'); $args = array( 'posts_per_page' => 3, 'offset' => 0, 'category' => implode(',',$selected), 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_mime_type' => '', 'post_parent' => '', 'post_status' => 'publish', 'suppress_filters' => true );
Hope that helps.
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!
We’re hard at work on ACF 6.1, and Beta 1 is now available 🚀— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.