Support

Account

Home Forums Front-end Issues Trouble in displaying category link

Helping

Trouble in displaying category link

  • Hi there,

    I have a fields group in which I have a text field and a taxonomy link, which is set to display only product categories with the radio buttons. Everything is displaying fine in WP Dashboard (a list of categories is displayed and I can choose one), but I have trouble in getting the link on the page.

    Here’s the code I tried:

     
    <?php
    		
        // vars
        $groupfield = get_field('group01');
        $shopid = get_sub_field('cat_link');         
    
           if( $groupfield ):?>
    
            <div class="content">
                <?php echo $groupfield['text01']; ?>
                <a href="<?php echo get_permalink( $shopid ); ?>" class="button">See</a>
            </div>
                            
           <?php endif;?>
    

    Any ideas what I’m doing wrong?

    This code also doesn’t show any content…

    
                     <?php echo '<pre>';
                     print_r( $shopid );
                     echo '</pre>';
                     die; ?>
    
  • For radio button fields, you’ll need to add ['value'] or ['label'] after the variable to show either the value or label:

    
    <a href="<?php echo get_permalink( $shopid['value'] ); ?>" class="button">See</a>
    

    For testing, you’ll want to grab the object which will include the values and labels:

    
    <?php
    
    $shopid_obj = get_sub_field_object( 'cat_link' );
    var_dump($shopid_obj);
    
    ?>
    

    The above will spit out the array of your radio button field so you can see what’s there.

    See more here: https://www.advancedcustomfields.com/resources/radio-button/

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

The topic ‘Trouble in displaying category link’ is closed to new replies.