Hi John,
many thanks. This works fine.
But how can I add a “read more” Link after each answer?
Example: <p>Read more about <strong><a href="<?php the_permalink(); ?>"><?= the_title(); ?></a></strong></p>
Hi,
does no one have an idea how I can solve the problem?
Unfortunately, it still doesn’t work. The commas are not output.
Here’s my complete code again:
<?php
$rows = intval(get_field('faq'));
if (have_rows('faq')) {
$count = 1;
?>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
<?php
while (have_rows('faq')) {
the_row();
?>
{
"@type": "Question",
"name": "<?php the_sub_field( 'question' ); ?>",
"acceptedAnswer": {
"@type": "Answer",
"text": "<?php the_sub_field( 'answer' ); ?>
}
<?php
if ($count < $rows) {
?>,<?php
}
$count++;
}
?>
]
}
</script>
<?php
}
?>
Hello John,
thanks for your help. Your code is still giving me a bug. At the end the closing ?>
is missing. I added it, then the output will be done. But now all entries are output without commas and not only the last one.
Hello John,
thank you for your prompt assistance.
I’ve tried both variants several times now, but it won’t work.
Can you please show me how to use both options with my code?
Thanks a lot!
Michael
Hello John,
thanks for the code. I have implemented it and replaced the corresponding fields (repeater_field, object_field & sub_field) with my data.
But now no more output is generated.
Have I forgotten anything else?
Hello John,
Thank you so much for your feedback.
I understand the problem with the nested loops. But I don’t understand your examples behind the links.
Maybe you can help me with a small example related to my code?
Many thanks
Okay, I found the mistake. It was just a silly missing / in the closing
Sorry, here’s the complete code.:
<?php $post_objects = get_field( 'field1' ); ?>
<?php if ( $post_objects ): ?>
<ul>
<?php foreach ( $post_objects as $post ): ?>
<?php setup_postdata( $post ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.