• Resolved cmdshiftdesign

    (@cmdshiftdesign)


    Using the Advanced Custom Fields plugin with the Repeater add-on. (http://www.advancedcustomfields.com)

    I have repeated field called “lists’ and within that a sub field called ‘spcl’

    I want a conditional statement w/in my template saying …. IF ‘spcl’ is there,
    DO THIS
    if not
    DO NOTHING

    since i am dealing with a subfield, im having trouble getting this to check for first the list field and then the sub field.. this is what i have right now…

    <?php
    if(get_field('lists') && get_sub_field('spcl'))
    {
    	echo '<p>POOP!</p>';
    }
    ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • While I’ve never heard of the plugin before now, their documentation is pretty straight forward. Give this a shot:

    <?php
    
    $lists	= get_field('lists');
    $spcl 	= get_sub_field('spcl');
    
    if( ($lists) && ($spcl) )
    {
    	echo '<p>POOP!</p>';
    }
    ?>
    Thread Starter cmdshiftdesign

    (@cmdshiftdesign)

    Thanks, but no dice.

    w/ my solution and this i can get it to work if i cam only calling for the ‘lists’ field, but once i also ask for the sub_field ….nope :/ GRF!

    Again, thanks though!

    Without seeing the rest of the code, I’d say that since it’s a repeating field, it’s probably being stored in an array and thus has to be broken out with a foreach.

    What do you get when you try to echo out the conditional functions?

    <?php
    
    echo get_field('lists');
    echo get_sub_field('spcl');
    
    ?>

    Do you get values for both? Also, does it maybe not process the HTML markup? Try removing the paragraph tags?

    Good luck lady! Feel free to shoot me credentials via email or whatever if you don’t figure it out within a couple hours. Should be home from work by then and available to toy with it.

    You’re gonna want to look at this documentation, as you’re on a repeater field (which is inherently different):

    http://www.advancedcustomfields.com/docs/code-examples/#wpshdo_7

    So you’d do something like …

    $lists = get_field( 'lists' );
    if( $lists ){
    	foreach( $lists as $list ){
    		if( $list['spcl'] ){
    			echo '<p>POOP!</p>';
    		}
    	}
    }

    it should trigger once for each instance of the repeater field, if spcl isn’t blank

    Thread Starter cmdshiftdesign

    (@cmdshiftdesign)

    Hey Dudes! Was JUST now able to get back to working on this and George, you win today!

    Thanks to all of you! <3

    Oh yeah, that too. George wins!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Conditional Statement (Advanced Custom Fields)’ is closed to new replies.