Home › Forums › Add-ons › Repeater Field › Only show post if subfield has certain value › Reply To: Only show post if subfield has certain value
I need some clarification what you are trying to do with your code above…
Because this: <?php if( get_sub_field(‘category’, 8) ): ?> …means that you are trying to check if post ID 8 has a sub field ‘category’.
If this is not what you want but instead want to see if sub_field ‘category’ has the value 8 you can do it like this:
<?php
$variable = get_sub_field(‘category’);
if ($variable && $variable == ‘8’) {
echo ‘Yes this post has a field category with value 8’;
}
?>
But as I’m not fully aware of your situation, I’m also thinking that you may be confusing actual wordpress categories and custom fields and if that’s the case, you code needs a whole different approach.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.