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.
Related
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/
I have a code chunk that is inside the_content(); I'm using acf repeater as well. So when I post a blog, I'll either use the_content(); or the acf field. I have h2 tag ( latest articles ) that I only want printed one time, but it's printing everytime I make a post.
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<div class="container">
<div class="row">
<div class="col-md-4 sidebar-r">
<?php echo the_content(); ?>
</div><!-- end sidebar-r -->
<?php
$i = $wp_query->post_count;
if($i <=1) {
echo '<h2 class="link-title">
<?php the_sub_field('link_title'); ?>,
</h2>';
}else{
echo '';
}
?>
<div class="col-md-8 links-wrap">
<?php if(have_rows('daily_links')): ?>
<?php while(have_rows('daily_links')): the_row(); ?>
<a href="<?php the_sub_field('link_url'); ?>" target="_blank">
<h2 class="link-title">
<?php the_sub_field('link_title'); ?>,
</h2>
<h3 class="link-source">
<?php the_sub_field('link_source'); ?>
</h3>
</a>
<?php endwhile; ?>
<?php endif; ?>
</div><!-- end links wrap -->
</div><!-- end row -->
</div><!-- end container -->
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
You'll see I tried using php to count the posts and if more than one post, don't print the tag, but couldn't figure out the exact logic and syntax.
I am honestly struggling a bit to understand exactly what you are trying to do and since I do not even have the posts and other key pieces of information so that I can properly replicate your issue so that I can help you better, this is a little bit challenging. That being said, looking into some ideas I came across another stackoverflow question/answer that might be relevant for you in catching the first post and does something to it. The answer to the referenced question instance was this:
<?php if (have_posts()) : $postCount = 1; while (have_posts()) : $postCount++; ?>
<?php if($postCount == 2) { ?>
// SOMETHING TO DO WITH FIRST POST
<?php } else { ?>
// SOMETHING TO DO WITH ALL OTHER POSTS
<?php } ?>
This was suggested by user Bora in this answer from 2013.
Let me know if that helped!
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; ?>
In the below code, I call fields from Advanced Custom Fields plugin and only the first two show 'home_title' and 'home_content'. After these two I run two different loops to show the latest posts in a given category. After those loops run there are 4 more fields from ACF called. 'donate_title' , 'donate_content' , 'mission_title' , 'mission_content'. Which are not showing up (not pulling any content at all).
If I move these ACF before running the loops they all show up correctly. So I imagine there is a problem with these following the loops but cannot find the reason.
<div class="main-site">
<div class="home-title-1">
<?php the_field('home_title'); ?>
</div>
<div class="home-content-1">
<?php the_field('home_content'); ?>
</div>
<div class="home-boxes-cont">
<div class="box-left">
<?php
query_posts('cat=4&posts_per_page=1');
while (have_posts()) : the_post(); ?>
<div class="bl-img">
</div>
<div class="bl-title">
<?php the_title(); ?>
</div>
<div class="bl-content">
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
</div>
<div class="box-middle">
<?php
query_posts('cat=5&posts_per_page=1');
while (have_posts()) : the_post(); ?>
<div class="bm-img">
</div>
<div class="bm-title">
<?php the_title(); ?>
</div>
<div class="bm-content">
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
</div>
<div class="box-right">
<div class="br-img">
</div>
<div class="br-title">
<?php the_field('donate_title'); ?>
</div>
<div class="br-content">
<?php the_field('donate_content'); ?>
</div>
</div>
</div>
<div class="mission-title">
<?php the_field('mission_title'); ?>
</div>
<div class="mission-content">
<?php the_field("mission_content"); ?>
</div>
In order to get custom field data from the original post after altering the global post data with your query_posts() calls, you need to reset your post data with the wp_reset_query() function. Place this function after each loop -
<?php while (have_posts()) : the_post(); ?>
...
<?php endwhile; wp_reset_query(); ?>
You are altering the global wp_query variable. When you do that and the the result is not is_single() then you cannot pull any ACF settings any longer.
Either reset the wp_query to its original setting for the page or store the vars in an array before you make any wp_query changes, and retrieve them as needed later in the code.
While I agree with Scriptonomy, you should really just use get_posts(). This is exactly what this function is designed to do... custom loops outside the main loop. You should rarely ever need to modify the global wp_query variable.
If you still want to use the_permalink() and the_title() without passing a post id, then scroll down the page to the section labeled "Access all post data" and you'll see how to use setup_postdata() to make it easier.
I'm new to Wordpress and PHP so not sure how to word this problem.
I'm developing a Wordpress blog with custom pages (2 column layout for the pages) and I'm using Advanced Custom Fields.
Anyways so I have a custom field called content_row which has a sub_field named row and that has 2 sub_fields named left_column and right_column.
For some reason I'm not able to pull the row content :(
My page.php code (on the first echo I'm getting a "bool(false)" on the screen):
<?php get_header(); ?>
<section style="margin-top:400px;">
<?php
if( get_field('content_row') ): ?>
<?php echo var_dump(has_sub_field('row')); ?>
<?php while( has_sub_field('row') ): ?>
<?php echo "test"; ?>
<?php endwhile; ?>
<?php endif; ?>
</section>
<?php get_footer(); ?>
Any ideas / thoughts? Let me know if you guys need to see more code... some screenshots below:
Got it figured out!
<?php while(the_flexible_field("row")): ?>
<?php if(get_row_layout() == "2_column"): // layout: Content ?>
<div class="content">
<?php the_sub_field("left_column"); ?>
<?php the_sub_field("right_column"); ?>
</div>
</div>
<?php endif; ?>