So I was able to fix the problem. However How can I hide filed that have as value NO?
Now the one with YES are rendered, but the one with NO generate empty white spaces
When I do that I get a syntax error.
This is what I wrote
<?php $value = get_field('doors'); ?>
<?php if ($value == 'YES') ?>
<div class="feature">With doors</div>
<?php endif; ?>
Now seems to work. Do I need to re-save all my posts again manually in order to have this rules applied?
May I add something to my question? Maybe it explain better my issue:
I am getting those posts in my CPT from somewhere (is an external software). The posts are automatically saved in WP with a title that looks like: title-one-2345
Is it possible to apply the rule you proved above automatically?
When I add this to my functions.php (I am using a Child theme) I get an error.
In the specific the error says syntax error, unexpected '=' ... on linke 54
On that line there is this
$post->post-title = $title;
BTW: I would like that all the posts are saved with the Value in the “title” field
You are attempting to use ACF to get a field that is not an ACF field. The only reason that it works at all is that it is a simple text field.
Since this is not an ACF field then you need to use get_post_meta() and you need to test the value to see if it is yes or no
$value = get_post_meta($post->ID, 'doors', true); if ($value == 'YES') ?><div class="feature">With doors</div><?php }
I will test this, thanks :). BTW, what do you men is not an ACF field?
I am using ACF to create the Text field called Doors …
Is placed someplace in the page outside the loop
<!-- intro -->
<div class="intro intro-home" id="intro-home">
<div class="container bloc-lg bloc-md-lg">
<div class="row align-items-start">
<div class="col-sm-4 col col-360">
<img />/img/lazyload-ph.png" data-src="<?php echo get_template_directory_uri(); ?>/img/placeholder-image.png" class="img-fluid mx-auto d-block lazyload" alt="placeholder image" />
</div>
<div class="col-sm-8 col">
<h1 class="mg-md btn-resize-mode h1-style">
<?php the_field( 'headline' ); ?>
</h1>
</div>
</div>
</div>
</div>
<!-- intro END -->
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.