[Plugin: Advanced Custom Fields] Field output first tests false, then is displayed
-
This one is weirding me out.
I have two nearly identical functions:
function GetSubTitle(){ $subTitle = get_field('sub-title'); if (!empty($subTitle)){ $output .= '<h3>'.$subTitle.'</h3>'; return $output; } else { //No subTitle, so skip the whole thing } }
and
function GetGuestAuthor(){ $GuestAuthor = get_field('guest_author_name'); if (!empty($GuestAuthor)) { echo '<span class="byline">'.$GuestAuthor.'</span>'; } else { //No Author, so skip the whole thing } }
They both work great in most of the places I’m using them in my template. However, when using these near each other, things get weird. GetSubTitle() is testing false, GetGuestAuthor() tests true and outputs correctly, and then GetSubTitle()’s output shows up. Here’s the template code:
<h1><?php the_title(); ?></h1> <?php GetSubTitle(); ?> <?php if(in_category('articles')){ ?> <div class="article-details"> <small><?php GetGuestAuthor(); ?></small> <small class="archive-dateline"><?php echo get_the_time('F jS, Y') ?></small> </div> <?php } ?>
Which then outputs:
<h1>Title</h1> <div class="article-details"> <small><span class="byline">Guest Author Name</span></small> <small class="archive-dateline">June 20th, 2012</small> </div> <h3>Article Sub-Title</h3>
I’ve tried switching the GetSubTitle() function around a bit, which didn’t do much. When I had it echo something during the else condition, it showed that right below the <h1> title, and still showed the requested string down below. I’ve also tried it with return instead of echo:
$output .= '<h3>'.$subTitle.'</h3>'; return $output;
when testing true, but that didn’t make difference.
Any ideas out there? I’m nearly to the point where I’m going to cheat them back into order with CSS, although I’d obviously prefer not to.
Thanks!
Z-247
https://www.ads-software.com/extend/plugins/advanced-custom-fields/
- The topic ‘[Plugin: Advanced Custom Fields] Field output first tests false, then is displayed’ is closed to new replies.