In the rubric I create a repeater + image field and try to display this content on the category page and the post page of this category, but nothing happens.

<?php if( have_rows('slide') ): while ( have_rows('slide') ) : the_row(); $image = get_sub_field('img'); $size = 'slider-inner'; if( $image ) { echo wp_get_attachment_image( $image, $size ); } endwhile; endif; ?> 

and so, where 'category' is the heading

 <?php if( have_rows('slide', 'category') ): while ( have_rows('slide', 'category') ) : the_row(); $image = get_sub_field('img'); $size = 'slider-inner'; if( $image ) { echo wp_get_attachment_image( $image, $size ); } endwhile; endif; ?> 

and so, where 9 is the rubric ID

 <?php if( have_rows('slide', 9) ): while ( have_rows('slide', 'category') ) : the_row(); $image = get_sub_field('img'); $size = 'slider-inner'; if( $image ) { echo wp_get_attachment_image( $image, $size ); } endwhile; endif; ?> 

Where is the mistake? How to get fields on the category.php page and on the single.php page?

And this also does not work

 <?php $queried_object = get_queried_object(); print_r( $queried_object ); if( have_rows('slide', 'poly_9') ): while ( have_rows('slide', 'poly_9') ) : the_row(); $image = get_sub_field('img'); $size = 'slider-inner'; if( $image ) { echo wp_get_attachment_image( $image, $size ); } endwhile; endif; ?> 

It gives only this and everything, the field does not receive:

 WP_Term Object ( [term_id] => 9 [name] => Полиэтилен [slug] => poly [term_group] => 0 [term_taxonomy_id] => 9 [taxonomy] => category [description] => [parent] => 6 [count] => 0 [filter] => raw [cat_ID] => 9 [category_count] => 0 [category_description] => [cat_name] => Полиэтилен [category_nicename] => poly [category_parent] => 6 ) 
  • and what is the common task? What exactly do you need to display these fields? maybe I can help if you explain in more detail. - malginovdesign
  • Thank you, I found a solution, I did not correctly specify the parameters. - korg

1 answer 1

Must be specified in the format of the "field", "taxonomy_ID taxonomy". For example, have_rows('slide', 'category_9'). If the output is in the archive file or category, you can:

 $queried_object = get_queried_object(); get_field('slide', $queried_object)