Wordpress ACF repeater field loop - php

I am trying to loop out a repeater field in my wordpress front-page template
But for some reason the div is empty and doesn't seem to work.
I am 100% sure my code is correct so there must be an issue.
Anyone has any idea what it could be?
This is how my loop looks like, the field keys are correct! :)
<?php
/**
* Template Name: Front Page Template
*/
?>
<?php while(have_posts()) : the_post(); ?>
<?php if( have_rows('achtergrond_afbeeldingen') ): ?>
<div class="slider-circles">
<?php while ( have_rows('achtergrond_afbeeldingen') ) : the_row(); ?>
<p id="slide1" data-bgimage="<?php the_sub_field('image'); ?>" class="transparent-circle slick-active"></p>
<?php endwhile; ?>
</div>
<?php endif; ?>
<?php endwhile; ?>
This is what my front-page.php looks like. The funny thing I've used this in an other project before and everything worked fine. Now my screen is just blank, I have no idea what's going on.

if have_rows('field_56e7d8bebb545') is really true, debug the_row();
var_dump(the_row());
You can view the_result, if is empty, maybe you must set a second parameter for have_row($field_name, $post_id)

field_56e7d8bebb545 is the field key, not the field name. The field name must be used in the have_rows() function. This can be found on the Advanced Custom Fields screen next to the label -

Try this one .. since you have not printed any such thing that can be displayed in browser .. you only provided the data attribute to div.
Write something inside inner HTML might see you repeater values
<?php
/**
* Template Name: Front Page Template
*/
?>
<?php while(have_posts()) : the_post(); ?>
<?php if( have_rows('achtergrond_afbeeldingen') ): ?>
<div class="slider-circles">
<?php while ( have_rows('achtergrond_afbeeldingen') ) : the_row(); ?>
<p id="slide1" data-bgimage="<?php the_sub_field('image'); ?>" class="transparent-circle slick-active"><?php the_sub_field('image'); ?></p>
<?php endwhile; ?>
</div>
<?php endif; ?>
<?php endwhile; ?>

Related

WordPress: Unable to read custom field that is part of a fields group

I added a new custom field to a fields group to be used only to render the homepage. When trying read and display the contents of this field with the code below, nothing happens. I am sure the way to read custom field is how it should be. I don't get any error message. Could you please help fix this? This is being done on a WordPress site.
<div class="bg-white-base relative pt-row pb-row pl pr">
<div class="wrap-x">
<div class="inside mini">
<?php if ( $headline = get_sub_field( 'slider_-_h1' ) ) : ?>
<h2 class="mb color-purple-base">
<?php echo $headline; ?>
</h2>
<?php endif; ?>
<?php if ( $subheadline = get_sub_field( 'slider_-_h2' ) ) : ?>
<h3 class="mb alt-heading h5">
<?php echo $subheadline; ?>
</h3>
<?php endif; ?>
<?php if ( $text_area = get_sub_field( 'slider-_shortcode' ) ) : ?>
<article class="body-area mt2x">
<?php echo $text_area; ?>
</article>
<?php endif; ?>
</div>
</div>
</div>
get_sub_field() is supposed to be use inside a loop. When you use a group, you may use a loop like :
while( have_rows('hero') ): the_row();
........
endwhile;
Everything is explained here : https://www.advancedcustomfields.com/resources/group/

Display custom field in product (wordpress)

I would like to display custom field on product page.
I made field (Advanced Custom Fields) and add a rule to display in selected category on Posts. It works, I placed there a simple text and would display in product page. In editor I edit template and pasted the code:
<?php the_field( 'my_info' ); ?>
Unfortunately nothing appears.
I try also something like this:
<?php
query_posts('cat=195&posts_per_page=1');
while (have_posts()) : the_post(); ?>
<?php if( get_field('my_info') ): ?>
<?php the_field('my_info'); ?>
<?php endif; ?>
<?php endwhile;
?>
After this code field display, but there is a problem with loading other page sections.
What I make wrong?
Since query_posts() is used, you have to put wp_reset_query(); after the endwhile(). Otherwise use WP_Query .
<?php
$query=WP_Query('cat=195&posts_per_page=1');
while ($query->have_posts()) : $query->the_post(); ?>
<?php if( get_field('my_info') ): ?>
<?php the_field('my_info'); ?>
<?php endif; ?>
<?php endwhile; ?>

Show only a specific page div Wordpress

I have this code:
<?php if(!is_home()): ?>
<div id="cristi"><?php echo get_the_content(1); ?></div>
<?php endif; ?>
<?php if(is_page(19)); ?>
<div id="contact2"><?php echo do_shortcode( '[contact-form-7 id="54" title="Contact form 1"]' ) ?></div>
<?php endif; ?>
I want to display a div only a page with ID 19.
I used is_page() function but not working.
Can you help me solve this problem please?
This is the site:
http://avocat.dac-proiect.ro/wp/
Thanks in advance!
is_page(ID) must be used outside The Loop in order to work properly, as defined here:
This Conditional Tag checks if Pages are being displayed. This is a boolean >function, meaning it returns either TRUE or FALSE. This tag must be used BEFORE >The Loop and does not work inside The Loop (see Notes below).
http://codex.wordpress.org/Function_Reference/is_page
$is_contact = is_page(19);
while ( have_posts() ) : the_post();
// do stuff
if ($is_contact)
// output contact form
endwhile;

Advanced custom fields not showing repeater

Hello so i have had problems showing ACF fields because of an custom plugin.
I did then find out that i can instead write:
<?php $outputtext= get_field('text'); ?>
<?php echo $outputtext; ?>
instead of
<?php get_field('text'); ?>
because this didn't work when plugin was activated.
So i have been searching for an answer for a while now and been testing the same way i did get fields to also show an repeater to. No success...
And yes i have been testing regular code wich is
<?php
// check if the repeater field has rows of data
if( have_rows('topp_yrken_referenser') ):
// loop through the rows of data
while ( have_rows('topp_yrken_referenser') ) : the_row(); { ?>
<div class="col-xs-12 col-sm-4">
<blockquote>
<?php // display a sub field value
the_sub_field('topp_yrke_referens');
?>
</blockquote>
</div>
<?php } endwhile;
else :
// no rows found
endif;
?>
This is how it worked before the custom plugin and stopped to work
How do i make something like this work like i made work with this instead?
Is there an name for this $this= get_field('text'); ?
<?php if (have_rows('topp_yrken_referenser')){ ?>
<?php while (have_rows('topp_yrken_referenser')) { the_row(); ?>
div class="col-xs-12 col-sm-4">
<blockquote>
<?php the_sub_field('topp_yrke_referens'); ?>
</blockquote>
</div>
<?php }; // while: ?>
<?php }; ?>
This is as barebones as the code can get.

Remove the_content From Wordpress Loop

I'm trying to figure out how to display a custom loop with only certain elements in a wordpress loop.
My loop currently contains the title, creation date, author & content.
However I am trying to remove the content for each post in the loop as I do not want it displayed in this list with no luck. I have even removed the_content() out of the loop & it still displays a listing of the post content under the looped section.
Any help would be greatly appreciated,
here is my code:
<?php query_posts('category_name=halloween &posts_per_page=6'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- IF articles then display them -->
<h6><?php the_title(); ?></h6>
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
<?php endwhile; else: ?>
<!-- IF no articles were created then show -->
NO Posts Present
<?php endif; ?>
I seemed to have found what i was missing in my code as there needed to be the following snippet of code required at the end of my loop which fixed the issue:
here is the code which I added after my endif
<?php wp_reset_query(); ?>

Categories