Support

Account

Home Forums ACF PRO get value from taxonomy term

Solved

get value from taxonomy term

  • i added two filed for woocommerce product category section.

    then in my template file taxonomy-product_cat.php i tried <?php the_field('side_box_title', $term); ?> and also <?php the_field('side_box_title'); ?> but value not coming

    i tried from http://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/ some code also but not coming. would you please support me

  • Hi @pagol

    Could you please set the second parameter manually like this:

    <?php the_field('side_box_title', 'product_cat_99'); ?>

    Where 99 is the ID of your product category.

    If you can do it, it means there’s something wrong with the $term variable you used there.

    Thanks!

  • this is my url for one product category page ../wp-admin/edit-tags.php?action=edit&taxonomy=product_cat&tag_ID=7&post_type=product from there i take ID 7 and put there. so code will be like now <?php the_field('side_box_title', '7'); ?>

    but nothing is come. remember this is woocommerce product category page

    few code from that page

    <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
    
    <h1 class="page-title">  <?php woocommerce_page_title(); ?></h1>
    <?php endif; ?>
    <?php
                /**
                 * woocommerce_archive_description hook
                 *
                 * @hooked woocommerce_taxonomy_archive_description - 10
                 * @hooked woocommerce_product_archive_description - 10
                 */
                do_action( 'woocommerce_archive_description' );
            ?>
            </div>
     <div class="cat-left-pan">
     <div class="cat-widget">
    <?php the_field('side_box_title', '7'); ?>
     </div>
  • Hi @pagol

    Could you please try the following code?

    <?php the_field('side_box_title', 'product_cat_7'); ?>

    You need to provide the taxonomy slug to the second parameter in order to make it recognized.

    Thanks!

  • thank you so much for quick reply. yes this work. but i need id dynamic. now all category page show same information because ID is i define hard coded. it need to dynamic base on category page. would you please support.

  • Hi @pagol

    Thanks for testing it out.

    It means there’s nothing wrong with ACF. The only problem now is how to get the product category ID on the product category page. By searching the internet, I found this solution. Maybe you can try it like this:

    $product_cat_object = get_queried_object();
    the_field('side_box_title', 'product_cat_' . $product_cat_object->term_id);

    Hope this helps.

  • cool. this is work. would you check bellow code correct way or not, have any better way to do for this. i have more than one filed.

    <h2><?php 
     $product_cat_object = get_queried_object();
    the_field('side_box_title', 'product_cat_' . $product_cat_object->term_id);
     ?></h2>
     <?php 
     $product_cat_object2 = get_queried_object();
    the_field('side_box_content', 'product_cat_' . $product_cat_object2->term_id);
     ?>
  • Hi @pagol

    If you need to get the fields from the same product category (the current product category page), you only need to set the $product_cat_object variable once like this:

    <?php $product_cat_object = get_queried_object(); ?>
    <h2><?php the_field('side_box_title', 'product_cat_' . $product_cat_object->term_id); ?></h2>
     <?php the_field('side_box_content', 'product_cat_' . $product_cat_object->term_id); ?>

    Hope this clears the thing up 🙂

  • wow.. superd…………. work nicely with minimum code. Thank you so much for great support

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘get value from taxonomy term’ is closed to new replies.