Home › Forums › ACF PRO › Using ACF Pro to create Posts Grid › Reply To: Using ACF Pro to create Posts Grid
You’re right, I misunderstood.
You need to get the values of the fields and then add a tax query when queying posts. Since you are looking at possibly multiple taxonomies then it will be a little complicated.
Set your fields to return term ID
The basic code would look something like this
$categories = get_field('my_category_field');
// make sure it is an array, if only one is
// selected it may return a single value
if (!is_array($categories)) {
$categories = array($categories);
}
$tags = get_field('my_tags_field');
if (!is_array($tags)) {
$categories = array($tags);
}
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'terms' => $categories
),
array(
'taxonomy' => 'post_tag',
'terms' => $tags
)
)
);
$query = new WP_Query($args);
For more information on tax_query see https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
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 use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.