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!
📣 “ACF Chat Fridays”
— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.