Home › Forums › ACF PRO › check if a certain value exists within query result › Reply To: check if a certain value exists within query result
Thank you, getting closer. I had a parse error with the code you provided and changed it slightly to that:
<?php
$args = array(
'taxonomy' => 'reisezeit'
);
$terms = get_terms($args);
$selected_terms = get_field('saison', false, false); // get only term IDs
if ($selected_terms) {
foreach ($terms as $term) {
if (in_array($term->term_id, $selected_terms)) {
echo 'Found';
}
else {
echo 'NotFound';
}
}
}
?>
This returns me: FoundFoundNotFoundNotFoundFoundFoundFoundFoundFoundFoundFoundFoundFoundFoundNotFound
which is a little bit strange since it’s 15 matches/non matches, but my taxonomy can have 16 values (12 months + 4 seasons). Querying like so:
<?php
$args = array(
'taxonomy' => 'reisezeit'
);
$terms = get_terms($args);
$selected_terms = get_field('saison', false, false);
print_r ($selected_terms);
?>
Gives me the ID’s of the selected terms:
Array ( [0] => 105 [1] => 95 [2] => 96 [3] => 97 [4] => 106 [5] => 98 [6] => 99 [7] => 100 [8] => 101 [9] => 107 [10] => 102 [11] => 103 )
which should be fine.
But how can I query in this result for a specific term ID? (as an end result I want to have 12 divs for all 12 months, but those months that are not selected greyed out // the selected ones marked with a color). So I need to do 12 in_array queries.
Thank you, Ralf
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.