ACF repeater field only show one row - advanced-custom-fields

I've got a problem with some code below
I use wordpress and the plugin ACF PRO.
I query some posts and in this posts their is a repeater field, but it seems that it shows only the first row of the repeater field 'evenement'.
I don't know if it's very clear ?
Somebody can help me.
Thanks
<?php $query = new WP_Query(
array(
'category__not_in' => array(520),
'category__and' => array(2905,1582),
'post_status' => array( 'draft'),
'post_type' => 'spectacles',
'lang' => 'fr',
'showposts' => -1,
'meta_key' => 'date_debut',
'orderby' => 'meta_value_num',
'order' => 'ASC')
);?>
<?php if($query->have_posts()) : while ($query->have_posts() ) : $query->the_post();?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<div id="bloc-picto">
<div class="item-picto">
<img src="<?php $picto = get_field('picto');if( !empty($picto) ): ?><?php echo $picto['url']; ?><?php else: ?><?php $image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id,'icon', true); echo $image_url[0]; ?><?php endif; ?>" width="40px" height="40px">
</div>
<div class="legend-picto">
<b><?php the_title(); ?></b>
<?php if( get_field('compagnie') ): ?>
<?php the_field('compagnie'); ?>
<?php endif; ?>
<br/>
<?php if( get_field('acces_star') ): ?>
<div style="font-size:10px"><?php the_field('acces_star'); ?></div>
<?php endif; ?>
<?php if( have_rows('evenement') ): while ( have_rows('evenement') ) : the_row(); ?>
<?php $post_object = get_sub_field('lieu_evenement');if( $post_object ):
$post = $post_object; setup_postdata( $post ); ?>
<i><?php the_title(); ?></i>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
</a>
<?php wp_reset_postdata(); ?>
<?php endwhile; else: ?>
<?php endif; ?>

I ran into a similar issue with the have_rows() loop only returning the first layout when essentially nesting one query within another.
My solution was to redefine the $post variable after each layout. For example:
$post = 123;
setup_postdata( $post );
if ( have_rows( 'components' ) ) {
while ( have_rows( 'components' ) ) {
the_row();
$course_tmpl_name = str_replace( '_', '-', get_row_layout() );
// include your layout php here
$post = 123; // redefine $post
}
}
wp_reset_postdata();

Related

Relationship Field meta_query Not Working Why?

<?php
/*
* Query posts for a relationship value.
* This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
*/
$doctors = get_posts(array(
'post_type' => 'star',
'meta_query' => array(
array(
'key' => 'location', // name of custom field
'value' => '"' . get_the_ID() . '"', // can you please explain this? my relationship field is currently Post Object not sure how
'compare' => 'LIKE'
)
)
));
?>
<?php if( $doctors ): ?>
<ul>
<?php foreach( $doctors as $doctor ): ?>
<?php
$photo = get_field('photo', $doctor->ID);
?>
<li>
<a href="<?php echo get_permalink( $doctor->ID ); ?>">
<img src="<?php echo $photo['url']; ?>" alt="<?php echo $photo['alt']; ?>" width="30" />
<?php echo get_the_title( $doctor->ID ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
base on the documentation of acf this is the right code but testing it not working why?..........................................thank you guys for helping me..

Show wordpress posts in a grid - side by side divs

I tried the code below to show posts in a grid , in side by side manner. but , as shown in the image divs appear broken.
<?php
$args = array( 'posts_per_page' => 15, 'offset'=> 1, 'category' => '' );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<div class="container" style="width:960px;margin :opx auo;">
<div class="colk" style="width:200px;height:150px;border-style:dotted;border-width:thin;display:inline-block;
float:left;clear:top;margin: 5px 20px 15px 0px;margin:10px;margin-top:0px;clear:top;" >
<?php the_title(); echo '<br>' ?>
</div>
</div>
<?php echo '<br>'; ?>
<?php endforeach; ?>
<?php
wp_reset_postdata(); ?>
How can i show the divs inline?
<?php
$args = array( 'posts_per_page' => 15, 'offset'=> 1, 'category' => '' );
$myposts = get_posts( $args );?>
<div class="container" style="width:960px;margin :0 auto;">
<?php foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<div class="colk" style="width:200px;height:150px;border-tyle:dotted;border-width:thin;display:inline-block;float:left;clear:top;margin: 5px 20px 15px 0px;margin:10px;margin-top:0px;clear:top;" >
<?php the_title();?>
</div>
<?php endforeach; ?>
</div>

Add category slugs to loop in wordpress

I don't know if I've used the best title for this question but I'm not sure exactly how to phrase it. I've successfully setup a filterable portfolio script on my site but I need to apply the appropriate class to each item. Right now I've got this.
<?php $loop = new WP_Query( array( 'post_type' => 'productions', 'posts_per_page' => -1 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="tile web all"> <?php the_post_thumbnail ( 'home-page' ); ?>
<h1><?php the_title(); ?></h1>
</div>
<?php endwhile; wp_reset_query(); ?>
The class "web" is just an example, it needs to be replaced by the slug(s) for the categories used for that particular post, as I've setup the filters to automatically show all the categories like this:
<div class="filters">
<p href="" data-rel="all">All</p>
<?php
$args = array(
'type' => 'productions',
'orderby' => 'name',
'order' => 'ASC',
'taxonomy' => 'production_type',
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<p data-rel="' . $category->slug.'">' . $category->name.'</p> ';
}
?>
Hopefully that is enough info for some help. Thanks.
This worked:
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="tile <?php
$terms = get_the_terms( $post->ID , 'production_type' );
foreach ( $terms as $term ) {
echo $term->slug;
echo ' ';
}
?> all"> <?php the_post_thumbnail ( 'home-page' ); ?>
<h1><?php the_title(); ?></h1>
</div>
<?php endwhile; wp_reset_query(); ?>

How to do a group by in the Wordpress?

I have a drivers post type which has a relationship called team. I want to group drivers by team so I can output them together in their groupings 'teams'. Hopefully that makes sense. I don't really understand the documentation I have a tried a few things but it seems to be missing details. This is what I have at the moment:
<?php
$type = 'drivers';
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'paged' => $paged,
'posts_per_page' => 12,
'ignore_sticky_posts'=> 0,
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
get_template_part( 'team-driver' );
endwhile;
?>
Here is my post type.
You may try this
<?php
// get all the categories
$cats = get_categories();
// loop through the categries
foreach ($cats as $cat)
{
// Get the cateogory ID
$cat_id= $cat->term_id;
//Header for the cateogry
echo "<h2>".$cat->name."</h2>";
// Make a custom wordpress query
query_posts("cat=$cat_id&post_per_page=12");
// start wordpress loop
if (have_posts()) : while (have_posts()) : the_post();
?>
<?php the_title(); ?>
<?php
echo '<hr/>';
endwhile;
endif; // End of WordPress loop
} // End of foreach loop through category
?>
If you want to get only one category (drivers) then
<?php
$cat_name = 'drivers';
$term = get_term_by('name', $cat_name, 'category');
$cat_id=$term->term_id;
query_posts("cat=$cat_id&post_per_page=12");
// start wordpress loop
if (have_posts()) : while (have_posts()) : the_post();
?>
<?php the_title(); ?>
<?php
echo '<hr/>';
endwhile;
endif;
?>
May be this one can help you
<?php
$cat_names = array('team1', 'team2', 'team3');
foreach($cat_names as $cat)
{
$term = get_term_by('name', $cat, 'category');
$cat_id=$term->term_id;
query_posts("cat=$cat_id&post_per_page=12");
// start wordpress loop
if (have_posts()) : while (have_posts()) : the_post();
?>
<?php the_title(); ?>
<?php
echo '<hr/>';
endwhile;
endif;
}
?>

Wordpress category, get all its posts

I am currently finish of my theme for a wordpress website that I am building, I am having a problem getting my categories to work though.
I am lost as to how I can loop through the current category if I am at a URL of say "/category/category-name" how would I loop the posts that belong to the category "category name".
I I do the following on my template
<p>Category: <?php single_cat_title(); ?></p> I get the following output
Category Name
So how do I loop through that categories posts?
Category.php
<?php get_header(); ?>
<article class="content">
<section class="top">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</section>
<section class="middle">
</section>
</article>
<?php get_footer(); ?>
page-news.php
<?php get_header(); ?>
<article id="content">
<section class="top">
<?php query_posts('post_type=news'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<section class="news">
<?php the_post_thumbnail(); ?>
<h2><?php echo strtolower(the_title()); ?></h2>
<span class="posted"><?php the_date("l jS M Y"); ?></span>
<?php
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
?>
<p><?php echo substr(strip_tags($content), 0, 400).'…' ; ?>Read More</p>
<p class="tags">
<strong>Categories:</strong>
<?php
$post_categories = wp_get_post_categories( $post->ID );
$cats = array();
foreach($post_categories as $c){
$cat = get_category( $c );
$cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
}
?>
<?php foreach($cats as $k => $v) : ?>
<?php echo $cats[$k]['name']; ?>
<?php endforeach; ?>
</p>
<p class="tags">
<strong>Tags: </strong>
<?php $tags = wp_get_post_tags($post->ID); ?>
<?php foreach ($tags as $tag) : ?>
<?php echo $tag->name; ?>
<?php endforeach; ?>
</p>
</section>
<?php endwhile; endif; ?>
<?php get_sidebar('news'); ?>
</section>
<section class="middle">
</section>
</article>
So page-news.php are where my news article reside, and the user can get the category using the link generated by <?php echo $cats[$k]['name']; ?>
I don't think you're outputting anything in category.php based on the code above. the_post() doesn't echo anything. It just puts the next record into $post. Try this...
<?php
get_header();
$cat = get_category(get_query_var("cat"));
var_dump($cat); //make sure that there really is a valid category and it's the right one
?>
<h1 class="page-title"><?php echo $cat->name?></h1>
<?php
if (have_posts()) {
while (have_posts()){
the_post();
<h2><?php the_title()?></h2>
<?php the_content()?>
<?php
}
} else {
?>
<p>No posts found!</p>
<?php
}
?>
<?php
get_footer();
?>
In page-news.php you should probably consider using the_category() to echo out the category links rather than constructing the links yourself -- that way you'll know that the links are valid....
<p class="tags"><?php the_category()?></p>
You can use this function inside your page template to loop the posts