Support

Account

Forum Replies Created

  • I’m running into a similar situation.
    I have a flexible content field (tabbed_content repeater) that allows the user to add a Tab Content section, and add tabs via a repeater.
    When they add a new post I’d like to be able to ‘auto populate’ that page with a tabb_content element, but still allow them to add/remove tabs (which is a repeater as mentioned).

    Is there any way to programmatically add this flexible content item of tabbed_content, with a predefined set of tabs..?

  • This is a solution for using GROUPS within a REPEATER. These are located in a Flexible Content field of Comparison – omit this IF statement if you’re not using within a Flexible Content field.

    Specifically, I have a REPEATER named ‘comparison_rows’ containing 4 Groups
    (The groups are named column_1, column_2, column_3 and column_4)

    This is so the user can create a comparison table, with the fields for each cell grouped together. Each cell contains an image, text and specific CSS class (which I use ‘type’ to change)

    Column_1 has these fields: text1, type1 and image1
    Column_2 has these fields: text2, type2 and image2
    and so on…

    The fields in each group are:
    text (text fields, go figure)
    type (select fields, with a list of classes, used to change classes on the elements)
    image (image fields returning the URL)

    Here’s is what worked:

    
    <?php elseif (get_row_layout() == 'comparison'): ?>
    	<?php if(have_rows('comparison_rows')): ?>
    		<?php while(have_rows('comparison_rows')): the_row(); ?>
    			<?php
    			$column_1 = get_sub_field('column_1'); // name of group 1
    			$column_2 = get_sub_field('column_2'); // name of group 2.. and so on			$column_3 = get_sub_field('column_3');
    			$column_4 = get_sub_field('column_4');
    			?>						
    				<div class="<?php echo $column_1['type1']; ?>">
    					<?php if ($column_1['image1'] ): ?>
    						<img src="<?php echo $column_1['image1']; ?>"  class="comparison-img"  />
    					<?php endif; ?>
    					<p><?php echo $column_1['text1']; ?></p>
    				</div>
    				
    				<div class="<?php echo $column_2['type2']; ?>">
    					<?php if ($column_2['image2'] ): ?>
    						<img src="<?php echo $column_2['image2']; ?>"  class="comparison-img" />
    					<?php endif; ?>
    					<p><?php echo $column_2['text2']; ?></p>
    				</div>
    				
    				<div class="<?php echo $column_3['type3']; ?>">
    					<?php if ($column_3['image3'] ): ?>
    						<img src="<?php echo $column_3['image3']; ?>"  class="comparison-img" />
    					<?php endif; ?>								
    					<p><?php echo $column_3['text3']; ?></p>
    				</div>
    				
    				<div class="<?php echo $column_4['type4']; ?>">
    					<?php if ($column_4['image4'] ): ?>
    						<img src="<?php echo $column_4['image4']; ?>"  class="comparison-img" />
    					<?php endif; ?>								
    					<p><?php echo $column_4['text4']; ?></p>
    				</div>
    					
    			<?php endwhile; ?> 
    	<?php endif; ?>
    <?php endif; ?>
    
    

    Maybe this will help someone down the road.

  • I’ve tried looping through the groups with:

    
    	<?php if( have_rows('column1') ): ?>
    	    <?php while( have_rows('column1') ): the_row(); 
    	        the_sub_field('type');
    	        the_sub_field('image')['url'];
    	        the_sub_field('text');
    	        ?>
    	    <?php endwhile; ?>
    	<?php endif; ?>
    

    and

    
    	<?php $column1 = get_sub_field('column1'); ?>
    		
    	<?php if( $column1 ): ?>
    		<?php echo $column1['text']; ?>
    
    		// let's see if the value is in the sub_field()			
    	        <?php the_sub_field('type'); ?>
    	        <?php the_sub_field('image')['url']; ?>
    	        <?php the_sub_field('text'); ?>
    	<?php endif; ?>
    

    🙁

  • Ok, solved it.
    Changed:

    
    <?php if (get_row_layout() == 'paragraph_content'): ?>
    

    To:

    
    <?php if (get_row_layout() == 'paragraph_content' && get_row_index() == 1): ?>
    

    and removed the break… all works as it should. No need for putting post, or cat, IDs in the fields!

  • If I remove the <?php break; ?> from the flex content loop, they all work, BUT if there is more than one paragraph content type, they’ll all show

  • Interestingly, the 1st post, of the SECOND loop for the flexible content DOES show the paragraph.. it’s just any consecutive posts in that get_posts loop, that don’t show the paragraph.

  • I have a similar issue, though with multiple Flexible Content loops on the Category page.

    My goal is to just get the first ‘paragraph’ content type for each post (these are custom post types with specific content defined for them, via ACF.

    So, if I use:

    
    <p class="lead">	
    	<?php if (have_rows('flexible_content_types')): ?>
    
    		<?php while (have_rows('flexible_content_types')): the_row(); ?>
    
    			<?php if (get_row_layout() == 'paragraph_content'): ?>
    				<?php echo truncate( get_sub_field('content' ), 120); ?>
         		<?php break; ?>
    			<?php endif; ?>
    
    		<?php endwhile; ?>
    
    	<?php  else: ?>
    		NO CONTENT
    	<?php  endif; ?>
    </p>
    

    It works, for the FIRST ONE.. then I run another loop:

    
    <?php
    	$featured = get_posts( array(
    		'post_type' 		=> 'post',
    		'numberposts'		=> 2,
    		'tag' 			=> 'featured',
    		'cat'                 => 3,
    		'ignore_sticky_posts' => 1,					
    		'offset'			=> 0
    	));
    		if ( $featured ): ?>
    			<?php foreach( $featured as $post ):  setup_postdata( $post ); ?>
    ... etc.. and run flex content loop here...
    

    and use the same flexible content loop from above.. doesn’t work on the second, third, etc. loops.

    Any ideas? What am I doing wrong here?

    IF I use the recommended code from above:

    $object = get_queried_object();
    $post_id = $object->taxonomy.’_’.$object->term_id;

    Then one of the flexible content loops works, the others do not…

    any suggestions ?

  • I’ve been tinkering and finally found something that works:

    
    		<form method="get" action="" onchange="submit();">
    			<div class="input-group">
    				<?php
    				global $wpdb;
    				$meta_key = 'item_oem';
    				$data = $wpdb->get_results($wpdb->prepare( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s", $meta_key) , ARRAY_N  ); ?>
    				<select class="custom-select" id="oems" aria-label="oems" name="item_oem" >
    					<option selected>Search By OEM</option>
    					<?php foreach( $data as $value ): ?>
    						<option value="<?php echo $value[0]; ?>"><?php echo $value[0]; ?> </option>
    					<?php endforeach; ?>
    			  </select>
    			  <div class="input-group-append">
    			    <a href="/inventory" class="btn btn-secondary" type="button">Clear Filter</a>
    			  </div>
    			</div>
    		</form>
    
    

    I’ll definitely look through your suggestions as well, and see which one works the best.. I don’t want to take a hit on performance just for a filter 🙂

    Thank you!

  • The purpose of the dropdown is to provide a way to filter the posts on the archive page, by OEM (the custom field value).

  • It’s a text field, added to each inventory post.

Viewing 10 posts - 26 through 35 (of 35 total)