Support

Account

Forum Replies Created

  • Yup, you can definitely utilize similar conditional logic. The only thing that might affect it is that the size of your GIF could be way off from the size of the other images so you might need to regular that on the ACF upload end to make sure your user is uploading something of similar width/height.

    <?php
    $images = get_field( 'gallery' );
    $size = 'thumbnail';
    
    if ( $images ) : ?>
         <ul>
    
         <?php foreach ( $images as $image ) :
    			
         $url = $image["filename"];
         $filetype = wp_check_filetype( $url );
    
    	if ( 'gif' == $filetype['ext'] ) {
    		$url = $image['url'];
    	} else {
    		$url = $image['sizes'][$size];
    	} ?>
              <li><img src="<?php echo esc_url( $url ); ?>" alt="Text describing my image here" /></li>
         
         <?php endforeach; ?>
         
         </ul>
    <?php endif; ?>
  • Hopefully I’m following your question correctly so this expands the process for you.

    The WP hierarchy will default to single.php – if you’d like to create different templates for each Custom Post Type, you could use that as a jumping off point but then create single-projects.php, single-services.php to add different markup and styling.

  • You would use a combination of getting a sub_field_object with getting values from an options page.

    So something like $label = get_sub_field_object('office_name')['label']; within your appropriate repeater.

  • Hi @irenehofer,

    Yup, it’s possible; there’s a few different strategies.
    One you could use something alone the lines of:

    $count = count( get_field( 'spalten' ) );
    echo $count;

    To then concatenate + create the class name you’d like and then echo it where desired.

    A more elaborate way is detailed in this thread, if you want to check that out as well. Let me know if there’s anything I can clarify!

  • Hi @charliechina,

    The strategy I used here was to set a counter to zero and then with each round of the while loop to add the new value to that variable. At the end, you can take that variable and output it where/within the markup needed.

    += is what is called an arithmetic operator.

    Intval will make sure that the variable is brought in as an integer.

    <?php
    if ( have_rows( 'products' ) ) :
    
    	$total = 0;
    
    	while ( have_rows( 'products' ) ) : the_row(); ?>
    		<?php
    		     the_sub_field( 'product_name' ); ?>: <?php the_sub_field( 'product_quantity' );
    
    		     $total += intval( get_sub_field( 'product_quantity' ) );
    
    	endwhile; ?>
    
    	<p><?php echo esc_attr( $total ); ?></p>
    <?php endif; ?>
  • @aunrea — What type of field is your ‘status’? Radio buttons or?

  • Ah, thanks for asking! Those values you circled are set via the values under “Choices” in the Radio Button field.

    As far as I know, I don’t think that the behaviour would shift whether you are using ‘group’ or not as that is an ACF thing rather than something field-specific. Flexible Content might achieve what you’d like because you would be deleting each component rather than activating/deactivating (if I’m understanding correctly). So that might achieve a similar goal in a slightly different way – just don’t know if that’s desirable for you/ your user.

    Also could be worth looking into hooks like save_post, update_field or update_value to achieve something along these lines depending on what you want to clear/keep?

    This thread might also be of use.

  • In this case I would check for the value of the field that sets the condition for the field you want to display. That way even if there is a previous value saved in the database, the one you’d like to be currently displayed will still show up.

    <article class="card">
    	<?php
    	// Variables.
    	$card = get_field( 'card' );
    	$button_type = get_field( 'card' )['button-type'];
    	?>
    
    	<?php if ( $button_type == 'file' ) { ?>
    
    		<a class="button" href="<?php echo $card['button-file']['url']; ?>"><?php echo $card['button-text']; ?></a>
    
    	<?php } elseif ( $button_type == 'email' ) { ?>
    
    		<a class="button" href="mailto:<?php echo $card['button-mail']; ?>"><?php echo $card['button-text']; ?></a>
    
    	<?php } else { ?>
    
    		<a class="button" href="<?php echo $card['button-url']; ?>"><?php echo $card['button-text']; ?></a>
    
    	<?php } ?>
    </article>
  • For your first issue, groupings are treated similar to repeater fields but there is a single row of data in that value.

    Visually, it appears as a repeater within a repeater.

    <?php
    
    // Check for grouping.
    if ( have_rows( 'price_information' ) ) :
    	while ( have_rows( 'price_information' ) ) : the_row();
    
    		// Check for repeater.
    		if ( have_rows( 'event_cost_structure' ) ) :
    
    			// Loop through the rows of data.
    			while ( have_rows( 'event_cost_structure' ) ) : the_row(); ?>
    
    				<p><?php the_sub_field( 'option_name' ); ?> : <?php the_sub_field( 'option_price' ); ?></p>
    
    			<?php
    			endwhile;
    		endif;
    	endwhile;
    else :
    	// No rows found.
    endif; ?>

    For the second issue, it seems to format the date correctly on my end…What are your organizations and settings in regards to the display/return format for the Date Picker?

  • Hi @Mikey2004,

    It sounds like this would be a case for a grouping of conditionals built within your Repeater field. This is used for: selects, checkboxes, booleans, and radio buttons.

    Just like you mentioned, you’d have a radio button or dropdown that would select the category of product at the top, which would then cause certain options to be available for you.

    You’d do this within your repeater & have your first option (radio/dropdown/etc.) And then list additional fields underneath almost as if you would want them ALL appearing. The only difference is that you then set rules for them under the ‘conditional’. “Show if _____”, etc. Otherwise, it won’t show as an option to pick anything from.

    Hope that helps! Let me know if I can clarify anything.

  • Does it shift anything if you adjust $images = get_field( 'slider_principal_banners', 4 ); to $images = get_field( 'slider_principal_banners' );?

    Neither the images nor the URL field will work for me otherwise on my end otherwise. If you’d like to set a max/min of four images, you could set that within the ACF field settings themselves rather than that line.

  • Hi @davidzack,

    Yup, you’re right – you can utilize img_caption_shortcode! The example from the WordPress codex is a good skeleton structure to work off of to add the markup you’d like to.

    Something to keep in mind is that you’ll need to pass a second parameter when getting your photo_credit field to target the media it is attached to.

    One way of getting the appropriate ID is to use preg_match & regex to split the number off before the $attr are defined in that example:

    preg_match( '/(\d+)$/', $attr['id'], $matches );
    $media_id = $matches[1];
    $credit = get_field( 'your_field_name', $media_id );

    From there you can add conditionals how you’d like & place it where you’d like within your markup. Let me know how it pans out!

  • Hi @jorenvh,

    Have you updated your version of ACF? It looks like this might have been solved recently according to this response.

  • Hi @cnd, did you get this sorted?

    When I experimented with the code you provided the conditional worked fine on my end. What is your repeater field attached or connected to?

  • Hi @mtm,

    Did you get this sorted? I can’t find that particular markup on the page you linked but your code is correct / works a-okay on my end.

  • Hi @titia2478,

    There’s a great example in the ACF Date Picker docs under “Advanced” that will help you achieve this!

    The example increases it by a day, so you could adjust accordingly for your needs to increase it by a year and then output that new date in your chosen format.

    (If you want to learn more about the PHP modify function, here are the docs for that as well).

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