Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am a big fan of Advanced Custom Fields plugin
http://www.advancedcustomfields.com/

I developed a site where there are 2 types of categories: normal and “custom” most of the categories display normally like any other site showing the posts in the archive.php page and some posts archive are displaying in a special “category” template which I created which is styled differently called: “category-projects.php

this is a special “archive” or “category” page which display different archive template for special posts.

this template works fine and using a function I created and everything looks good.

Now, I am trying to create ACF slider using the great repeater that I have in this special category template. so I created this new group called “post_slider_projects” and a simple repeater field for images called: “post_slide_projects

Now, I assigned the rules to appear in category and I see it when I am browsing my admin categories section.

until this point everything is working. the only problem is that it is not displaying when I look at the site in this special category page..

here is the code I was using to display it:

<?php if(get_field('post_slider_projects')){ ?>
<div class="post-section">
      <section class="flexslider">
        <ul class="slides">
          <?php while( has_sub_field('post_slider_projects') ){ 
            $post_slide_projects = get_sub_field('post_slide_projects');
            ?>
          <li class="latest-post"> <img alt="" src="<?php echo $post_slide_projects;?>"/> </li>
          <!--latest-post-->
          <?php } ?>
          <?php } else{ ?>
           <img alt="" src="<?php bloginfo('template_directory'); ?>/assets/images/slider-img1.jpg"/>
           <?php } ?>
        </ul>
      </section>
    </div>
<?php } ?>

Any help will be appreciated
Thanks a lot

share|improve this question

closed as off-topic by kaiser Jun 20 at 12:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

up vote 0 down vote accepted

The ACF API functions normally work with the current post's ID. Taxonomies and Users work a bit differently, you have to supply the ID of the object you want to fetch fields from.

$category_id = 'category_' . get_queried_object_id();
$field = get_field( 'post_slider_projects', $category_id );

See get_field in the documentation for more info.

share|improve this answer
    
I used your tip here and it did the trick.. I will post my solution below. thanks! –  gil hamer May 2 at 11:24

So, with the tip I got from @Milo above and some modification I made myself I ended up with the following working code:

<div class="post-section">
      <section class="flexslider">
        <ul class="slides">
          <?php 
          $category_id = 'category_' . get_queried_object_id();
          $field = get_field( 'post_slider_projects', $category_id );
          if($field){
          while( has_sub_field('post_slider_projects', $category_id) ){ 
          $post_slide_projects = get_sub_field('post_slide_projects', $category_id);
         ?>
          <li class="latest-post"> <img alt="" src="<?php echo $post_slide_projects;?>"/> </li>
          <?php } ?>
          <?php } else{ ?>
           <img alt="" src="<?php bloginfo('template_directory'); ?>/assets/images/slider-img1.jpg"/>
           <?php 
        } ?>
        </ul>
      </section>
    </div>

Hope it helps anyone!

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.