Support

Account

Home Forums Add-ons Repeater Field Output Taxonomy Link URL

Solving

Output Taxonomy Link URL

  • Hi …

    Am using the following code to try and output a link to the Woocommerce category but I cannot get the term_object to output anything – any pointers where I cam going wrong?

    I have a sub field which is selecting a single category from the standard ‘product_cat’ in WooC.

    <?php 
      if (have_rows('feature_categories')) {
        while (have_rows('feature_categories')) {
          the_row();
          $term = get_sub_field('link_category');
          $taxonomy = 'product_cat';
          $term_link = get_term_link($term, $taxonomy);
          $image = get_sub_field('category_image');
          ?>
                        
                        <div class="col-xs-12 col-md-4"><a href="<?php echo $term_link; ?>">
                <?php echo wp_get_attachment_image( $image, 'webblock' ); ?>
                <h4><?php the_sub_field('category_title'); ?></h4></a>
                </div> 
            
          <?php
        } 
      } 
    ?>

    Thanks in advance for any help!

  • Where is the field feature_categories located? On a post? On an options page? On a term?

  • Hi John ….

    It is on the front_page template – ie the home page. I simply want a block of 6 images with h3’s which all link to the chosen category in WooCommerce.

    Thanks in advance.

    Matt

  • If the images are not on the page that is being shown and you are trying to get fields that are on a term page then you need to supply the correct id.

    Example: $image = get_sub_field('category_image', $term);

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

You must be logged in to reply to this topic.