Support

Account

Home Forums General Issues pull sub field from previous post if no subfields found

Solved

pull sub field from previous post if no subfields found

  • is this possible?

    In my code I would love to pull the sub fields from a previous post if the current post has no subfields in the same repeater.

    $speakers = get_field('event_speakers');
    if( $speakers ){ 
         foreach( $speakers as $speaker ): 
    	if (get_field('speaker-front-page', $speaker->ID)){
                if ($i % 3 == 1){ 
                    $speakerdiv = 'av_one_third first';
    	     }else{
    	         $speakerdiv = 'av_one_third';	
    	     }
     
                echo '<div class="flex_column '.$speakerdiv.' flex_column_div">';
                echo do_shortcode("[av_image src='". get_field('speaker-photo', $speaker->ID)."' attachment='' attachment_size='full' align='center' animation='pop-up' styling='' hover='av-hover-grow' link='".get_the_permalink($speaker)."' target='' caption='' font_size='' appearance='' overlay_opacity='0.4' overlay_color='#000000' overlay_text_color='#ffffff'][/av_image]" );
                echo do_shortcode("[av_heading tag='h2' padding='10' heading='". get_the_title($speaker->ID)."' color='' style='blockquote modern-quote modern-centered' subheading_active='subheading_below' subheading_size='15']". get_field('speaker-company', $speaker->ID)."[/av_heading]");
    echo '</div>';
    	     $i++;
    	}else{ 
    	    //else if speaker is not front page do not show
    	}	
        endforeach; ?>
        </div><div class="clear"></div>
    
        <?php
    } else {
    // here would be the code to pull the subfields from the previous post
    }?> 
    <div class="clear"></div><hr />
  • 
    $speakers = get_field('event_speakers');
    if( $speakers ){
      // ... snip
    } else {
      $prev_post = get_previous_post();
      if ($prev_post && get_field('event_speakers', $prev_post->ID)) {
        $speakers = get_field('event_speakers', $prev_post->ID);
        // repeat of speaker loop code here
      }
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘pull sub field from previous post if no subfields found’ is closed to new replies.