Thank you, this was perfect. Exactly what I needed!
OKay, taking some guidance from here: http://support.advancedcustomfields.com/forums/topic/how-to-output-a-shortcode-in-an-input-field/
I did this:
<?php
global $wp_query;
$postid = $wp_query->post->ID;
$trailer = get_field( "trailer" );
echo do_shortcode("$trailer");
?>
Now it is outputting the shortcode from the custom field and printing it, but it does not execute it. I changed the Formatting for the field to No Formatting, but all it did is return the shortcode’s square brackets as HTML entities.
For the record, I did attempt using [acf field="{$trailer}"]
In a text widget by supporting it with add_filter( 'widget_text', 'do_shortcode');
in functions.php but it doesn’t work. Likely because the sidebar is outside the loop and there is not data.
This is my fault and is entirely a CSS issue. I was float:left on the internal li elements and that caused the issue. Not and ACF concern.
Marking this resolved, and you can delete this thread when you get a chance.
After doing some searching, I’m not any closer, but have read a lot about adding divs around each set of a php loop. However, I’m still struggling to make it work.
Somehow I solved this. I read through the info on the repeater plugin page again and modified my code. Didn’t see any obvious changes, but this snippet is working now.
<?php if(get_field('summary_section')): ?>
<div class="section-head"><h2>Summary</h2></div>
<?php while(has_sub_field('summary_section')): ?>
<ul>
<li class="bulletin-data-item"><h3>Bulletin Summary</h3><?php the_sub_field('bulletin_summary'); ?></li>
<li class="bulletin-data-item"><h3>Location</h3><?php the_sub_field('location'); ?></li>
<li class="bulletin-data-item"><h3>Report Number</h3><?php the_sub_field('report_number'); ?></li>
<li class="bulletin-data-item"><h3>Incident Date</h3><?php the_sub_field('incident_date'); ?></li>
<li class="bulletin-data-item"><h3>Incident Time</h3><?php the_sub_field('incident_time'); ?></li>
</ul>
<?php endwhile; ?>
<?php endif; ?>
I’ve somehow gotten rid of the endwhile syntax error by cleaning up the comments elsewhere in the template.
But I’m still left with no data displaying. I’ve fleshed out the snippet with the rest of the fields from that repeater field. This is the full code bit that I currently have, but still nothing displays.
<div class="patrol-bulletin-data">
<?php if( get_field('summary_section') ): ?>
<php while ( has_sub_field('summary_section') ): ?>
<div class='summary-data'>
<?php the_sub_field('bulletin_summary'); ?>
<?php the_sub_field('location'); ?>
<?php the_sub_field('report_number'); ?>
<?php the_sub_field('incident_date'); ?>
<?php the_sub_field('incident_time'); ?>
</div>
<php endwhile; ?>
<?php endif; ?>
</div>
That’s right on the money. Thank you for the quick reply!
As an update to this, this is the snippet I’m currently using, but it is not working.
<?php $fields = get_field_objects();
if( $fields != "")
{
foreach( $fields as $field_name => $field )
{
echo '<div class="single-custom-field">';
echo '<h2>' . $field['label'] . '</h2>'; echo $field['value'];
echo '</div>';
}
}
?>
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.