Support

Account

Forum Replies Created

  • Right. Makes sense. Thanks!

    For anyone who might stumble on to this, here’s the final code I ended up using:

    function get_team_members() { 
    	
    global $post;
    	
    if ( have_rows( 'team_members' ) ) { 
        $output = '<div id="team-grid">';
    	while ( have_rows( 'team_members' ) ) : the_row(); 
    		$post_object = get_sub_field( 'team_member' );
    		if ( $post_object ) {
    			$post = $post_object;
    			setup_postdata( $post );
                $headshot = get_field( 'headshot' );
    				$output .= '<div class="team-member">';
                        $output .= '<a href="' . get_the_permalink() . '">';
                            if ( $headshot ) {
                                $output .= '<img src="' . $headshot['url'] . '" alt="' . $headshot['alt'] . '" />';
                            }
                        $output .= '</a>';
                        $output .= '<div class="team-member-info">';
                            $output .= '<div class="team-member-name">' . get_field( 'name' ) . '</div>';
                            $output .= '<div class="team-member-title">' . get_field( 'title' ) . '</div>';
                        $output .= '</div>';
                    $output .= '</div>';
    			wp_reset_postdata();
    		}
    	endwhile;
    	$output .= '</div>';
    }
    	
    // return data
    return $output;
    
    }
    add_shortcode( 'show-team-members', 'get_team_members' );
  • Without the global $post; I wouldn’t have been able to figure it out. I’m curious why that is needed in this format, but not if I were putting it directly on the page, like this:

    <?php if ( have_rows( 'team_members' ) ) : ?>
    	<?php while ( have_rows( 'team_members' ) ) : the_row(); ?>
    		<?php $post_object = get_sub_field( 'team_member' ); ?>
    		<?php if ( $post_object ): ?>
    			<?php $post = $post_object; ?>
    			<?php setup_postdata( $post ); ?> 
    				<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    			<?php wp_reset_postdata(); ?>
    		<?php endif; ?>
    	<?php endwhile; ?>
    <?php else : ?>
    	<?php // no rows found ?>
    <?php endif; ?>

    Does that have to do with the shortcode vs. on page code?

  • Two things were wrong (three, counting the missing global $post; line) :

    1) I was using the_permalink() instead of get_the_permalink(), and that was causing the output buffer.

    2) I had to append each row to a final output variable. So I added this at the end of the while loop: $final_output .= $output; Then this at the end to return: return $final_output;

    Thanks for your help John!

  • Thank you! That got me closer.

    I’m still seeing the output buffer at the top of the page (although the URLs are correct, now), and only one row (post) is showing, without the permalink where it should be. Any idea why all of the rows aren’t showing up, except in the output buffer (showing the permalinks) at the top of the page?

  • Of course it was as easy as sliding the Save Terms button to on.

  • Turns out I was making it more complicated than it needed to be. This did the trick:

    $user_query = new WP_User_Query( array( 
    					'role' => 'Member',
    					'meta_key' => 'last_name',
    					'orderby' => 'meta_value',
    					'order' => 'ASC',
    
    					'meta_query' => array(
    					  array(
    						'key' => 'publish_publically',
    						'value' => true
    					  ),
    						array(
    						'key' => 'sector',
    						'value' => $_POST['sector-select'],
    						'compare' => 'LIKE'
    					  )
    					)
    
    				) );
Viewing 6 posts - 1 through 6 (of 6 total)