Home › Forums › General Issues › Custom field display on "php if" variable › Reply To: Custom field display on "php if" variable
Hi guys I think I figured it out while tinkering last night.
What I’ve done is add the summary field as a required entry for posts in the Reviews category (does ACF also apple that to subcategories in that main category?) by setting the rules as
Post category > is equal to > Reviews
and added this code to my page:
<?php if( get_field( "review_summary" ) ): ?>
<h3><?php _e('Summary'); ?></h3>
<p><?php the_field( "review_summary" ); ?></p>
<?php endif ?>
From what I see it seems to be working. If you guys notice that isn’t going to achieve what I’m looking for please let me know, or if the echo code above is a better choice. I tried that code and it didn’t put the proper h3 text style on the title.
But from what I can see it adds the summary field and h3 title only to posts that have something in the summary field. Is that right? Or is it trying to display it regardless, just without content? I guess that wouldn’t make sense because the title Summary would show up if that were the case.
Thanks.
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 wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 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.