We're merging with GenerateBlocks! Learn more here.

[Resolved] Custom Field repeater/URL output

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Custom Field repeater/URL output

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #5535
    Janek
    Participant

    Hey Tom,

    I’ve got another PHP dilhemma using custom fields. I’m trying to use a repeater to output links that the client feeds into a custom field in the backend of the site.
    The documentation seems to think its straight forward but I cant get it to work.
    https://www.advancedcustomfields.com/resources/repeater/

    The code I have used wont clear in snippets:

    add_action( 'wpsp_after_content', 'tu_add_material' ); 
    function tu_add_material() {
    
    if( have_rows( 'related_material' ) ): ?>
    while( have_rows('related_material') ): the_row();   
      // vars
      $link = get_sub_field('link');
      ?>
           if( $link ): ?>
    		  <a class="related-material" href="<?php echo $link['link']; ?>" target="<?php echo $link['target']; ?>"> <?php echo $link['title']; ?> />   
     <?php endwhile; 		 
    <?php endif; 
    }
    

    I’m sure this is a complete abomination of PHP and I’m wondering if you could lend a hand.

    Ideally what this should do is take URLS that the client inputs and then output them as clickable buttons on the front end.

    I’m borrowing some code from their documentation on link custom fields as well.
    https://www.advancedcustomfields.com/resources/link/

    But simply cant get anything to work correctly. :'(

    No hurry on this one, just working on improvements on my staging site so take your time. 🙂

    Happy to give you access to the back end of the site, you still have a admin account active there from last time.
    http://staging.janek-dev.flywheelsites.com/

    Thanks again for your help and all your previous help as well. I would be completely screwed without you! 🙁

    #5546
    Tom
    Keymaster

    Hi there,

    Give this a shot instead:

    add_action( 'wpsp_after_content', 'tu_add_material' ); 
    function tu_add_material() {
    	if ( have_rows( 'related_material' ) ) :
    		while( have_rows('related_material') ): the_row();   
    
    			$link = get_sub_field('link');
    
    			if ( $link ) : ?>
    				<a class="related-material" href="<?php echo $link['link']; ?>" target="<?php echo $link['target']; ?>"> <?php echo $link['title']; ?> </a>
    			<?php endif;
    		endwhile; 		 
    	endif; 
    }
    #5552
    Janek
    Participant

    Interestingly it doesn’t output anything on the front end. I looked over the code and nothing seems to be out of order. Any thoughts? 🙁

    #5556
    Tom
    Keymaster

    I assume link is the ID of your sub field? And that it has its own sub fields named link, target and title?

    #5574
    Janek
    Participant

    Sorry for the late reply.

    Yes I believe these are the correct ID’s. I’ve just doubled checked them and there is a sub field called link, however the target and title is provided by setting the field type to Link. The input on a post using the custom field would show WordPresses’s standard hyperlink window which in turn would provide data for the link, target and title fields.

    I took a screenshot of the custom field post input options here:
    https://drive.google.com/open?id=1SAuM1qX5XY-pw0DggNS7Ay27sCsVkMpn

    As well as a screenshot of the custom field setup in the ACF plugin here:
    https://drive.google.com/open?id=1QT_jpgeBvQIrTaPgBMC7BqfF8zlSzcYt

    Perhaps that provides a better idea than my description?

    If nothing jumps out at you, it might be time to try a different approach rather than using the repeater field I’ll try to get this working with a single entry.

    #5579
    Tom
    Keymaster

    I’m afraid nothing is immediately jumping out at me.

    Have you tried the ACF forums?

    #5581
    Janek
    Participant

    I’ve had a browse, but didnt find anything. I’ll take a better look and maybe post up something there.

    Thanks for your help as always, its appreciated! 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.