Home › Forums › Front-end Issues › Options page repeater field on a taxonomy template
Hi guys,
I’m making an image slider that I want to appear on a specific category page.
The slider fields are currently stored on an option page as a repeater.
The fields work fine on the homepage template, but when I copy the code to the category.php template, it doesn’t work.
Anyone know why this might be?
Code:
<!-- Start homepage slider -->
<div class="home-banner flexslider-home">
<ul class="slides">
<?php if(get_field('video_slider', 'option')): ?>
<?php while(has_sub_field('video_slider', 'option')): ?>
<?php $image = get_sub_field('image');?>
<li class="home-lead-image">
<a href="<?php the_sub_field('link'); ?>">
<img class="img-responsive upsize" style="visibility: hidden;" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"/>
<img class="img-responsive parallax upsize" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"/>
<div class="container-fluid">
<div class="col-sm-6">
<h1><?php the_sub_field('text'); ?></h1>
</div>
</div>
</a>
</li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
</div>
<div class="container-fluid">
<div class="banner-direction-nav">
<a class="prev">◀</a>
<a class="next">▶</a>
</div>
</div>
<!-- End homepage slider -->
It gets into the IF statement fine, but not the WHILE.
Anyone had any experience with this?
Cheers
Saul
Interesting it’s working on the homepage, the syntax seems like it would need to be tweaked to:
<!-- Start homepage slider -->
<div class="home-banner flexslider-home">
<ul class="slides">
<?php if (have_rows('video_slider', 'option')): ?>
<?php while(have_rows('video_slider', 'option')): the_row(); ?>
<?php $image = get_sub_field('image');?>
<li class="home-lead-image">
<a href="<?php the_sub_field('link'); ?>">
<img class="img-responsive upsize" style="visibility: hidden;" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"/>
<img class="img-responsive parallax upsize" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"/>
<div class="container-fluid">
<div class="col-sm-6">
<h1><?php the_sub_field('text'); ?></h1>
</div>
</div>
</a>
</li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
</div>
<div class="container-fluid">
<div class="banner-direction-nav">
<a class="prev">◀</a>
<a class="next">▶</a>
</div>
</div>
<!-- End homepage slider -->
Thanks for the reply, I updated the syntax, still works on homepage.php but not category.php
Weirdly when I dump the video_slider field on the category page I get this:
string(1) "2"
the “2” bit seems to be a count of the array, when there are three rows the dump updates to:
string(1) "3"
When I run the same dump code on homepage.php it returns the data correctly.
I seem to be able to get other standard text option fields on category.php, maybe it’s a combination of it being an option and a repeater field?
After some searching I found this post: http://support.advancedcustomfields.com/forums/topic/repeater-on-options-page-returns-count/
Which doesn’t directly apply to me as the code isn’t in functions.php, but it does imply that the repeater field “is not yet loaded and can’t run it’s custom load_value logic”.
I made the category page template in question (category-music.php) after installing ACF and creating the fields, do I have to register the new templates somehow?
Interesting, your new template shouldn’t need to be registered – if it’s loading it should be set.
Have you tried your code within the init hook like @elliot mentioned in that post?
add_action('init', function() {
?>
<?php if(get_field('video_slider', 'option')): ?>
<?php while(has_sub_field('video_slider', 'option')): ?>
<?php $image = get_sub_field('image');?>
<li class="home-lead-image">
<a href="<?php the_sub_field('link'); ?>">
<img class="img-responsive upsize" style="visibility: hidden;" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"/>
<img class="img-responsive parallax upsize" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"/>
<div class="container-fluid">
<div class="col-sm-6">
<h1><?php the_sub_field('text'); ?></h1>
</div>
</div>
</a>
</li>
<?php endwhile; ?>
<?php endif; ?>
<?php
});
Still nothing, weirdly it doesn’t fire anything from within that init function. Maybe that only works in functions.php?
After more Googling around, I found this:
I already had something similar in my functions.php, but it obviously wasn’t quite right. This is the correct code:
//Include CPT In Categories Pages
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$post_types = get_post_types( '', 'names' );
$query->set( 'post_type', $post_types);
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types');
Still, respect for the help ractoon!
The topic ‘Options page repeater field on a taxonomy template’ is closed to new replies.
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.