Home › Forums › Front-end Issues › get_field stops working when moving to WPML › Reply To: get_field stops working when moving to WPML
Hi elliot
Thanks for your hints. This set me on the right track.
I had to change two things. First i had to use
$post_objects = get_field('snippet_list',false,false);
to get the correct arry of post Ids
Second i had to use
foreach( $post_objects as $postID):
$post = get_post($postID);
to get the correct posts.
So the whole code looks like this at the end:
<div class="row product-single-row snippets">
<?php $post_objects = get_field('snippet_list',false,false);
if( $post_objects ):
$counter_tab = 0; ?>
<div class="span12">
<ul class="nav nav-tabs nav-snippets">
<?php foreach( $post_objects as $postID):
$post = get_post($postID);
$counter_tab++;
setup_postdata($post); ?>
<li><a href="#snippet<?php echo $counter_tab ?>" data-toggle="tab"><?php the_field('snippet_label'); ?></a></li>
<?php endforeach;
$counter_tab = 0; ?>
</ul>
<div class="tab-content">
<?php foreach( $post_objects as $postID):
$post = get_post($postID);
$counter_tab++;
setup_postdata($post); ?>
<div class="tab-pane fade" id="snippet<?php echo $counter_tab ?>">
<?php echo get_the_content(); ?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php wp_reset_postdata();
endif; ?>
</div>
I’m not sure, this is the optimal solution, but at least it works the way I expect.
Thanks again. I realy appreciate your help.
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.