• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Advanced Custom fields Post Object problem

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Advanced Custom fields Post Object problem

This topic is: not resolved

Tagged: ACF, advanced custom fields

  • This topic has 4 replies, 2 voices, and was last updated 9 years, 11 months ago by agelfand.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • November 10, 2016 at 10:22 am #195991
    agelfand
    Member

    Hi, I am trying to incorporate ACF into the Metro theme. (I am rebuilding an existing site using Genesis; the code I am now asking about worked in that theme).

    I can get the simple custom field data to display, but I am having a problem getting the function to loop through multiple Post Objects. Here is the tnire function; it outputs custom field data after the main content on a custom post. The Post Objects are for a You May Also Like section. The author selects any number of posts in the ACF multi-select filed and then I output them in a nice list.

    When I used ACF's debug snippet, I wasable to verify that the Post Object data does exist. But when I try to pull in my Post Object query, all I get is the current post's data repeated over and over again, not the posts that were selected in the ACF field.

    My guess is that the problem is creating a seconday query loop in Genesis, but I just don't know what specifically is wrong with what I am doing. Have not found documentation anywhere on the interwebs about Post Objects and Genesis. THANKS in advance!

    add_action ('genesis_entry_content', 'etb_acf_posts' );
    function etb_acf_posts() {
    	if (!is_singular(array('speakers','live_arts','event_production','films','presentations')) ) {
    		return;
    	}
    	// else
    	
    	{
    		$bookinglink = get_field('booking_url');
    	 echo '<a href="'.$bookinglink.'">';
    					$btntext = get_field('booking_button_text');
    					if ($btntext == '') { 
    					echo 'Book ';
    				echo the_title();
    					} else  {
    				echo $btntext; }
    				echo '</a>'; 
    				
    
                    
    		$video1 = get_field( 'video_one');
    		if( isset($video1) &amp;&amp; $video1 != '' ){
    		  echo '&lt;h4&gt;Video Gallery&lt;/h4&gt;';
    	  echo '&lt;div class="one-third first"&gt;';
    	  
    	  echo $video1;
        echo '&lt;/div&gt;';
    		}
    	 $video2 = get_field( 'video_two');
    	 if( isset($video2) &amp;&amp; $video2 != '' ){
    	 echo '&lt;div class="one-third"&gt;';
    	  $video2 = get_field( 'video_two');
    	  echo $video2;
        echo '&lt;/div&gt;';	
    	 }
    	  $video3 = get_field( 'video_three');
    	  if( isset($video3) &amp;&amp; $video3 != '' ){
    	 echo '&lt;div class="one-third"&gt;';
    	  $video3 = get_field( 'video_three');
    	  echo $video3;
        echo '&lt;/div&gt;';
    	  }
    	  echo '&lt;div class="clear"&gt;&lt;/div&gt;';	
    		$gallery_id = get_field('nextgen_gallery_id');
    		if( isset($gallery_id) &amp;&amp; $gallery_id != '' ){
    	  echo '&lt;h4&gt;Image Gallery&lt;/h4&gt;';
        echo "&lt;div class=\"post-gallery\"&gt;";
       //  echo nggShowGallery( $gallery_id ); // Display the gallery
      echo do_shortcode( $gallery_id );
        echo "&lt;/div&gt;&lt;div class='clear'&gt;&lt;/div&gt;";
      }
      	echo '&lt;div class="post"&gt;&lt;h4&gt;Topics&lt;/h4&gt;';
    			function mytheme_filter_tags( $term_links ) {
        $result = array();
        $exclude_tags = array( 'featured' );
        foreach ( $term_links as $link ) {
            foreach ( $exclude_tags as $tag ) {
                if ( stripos( $link, $tag ) !== false ) continue 2;
            }
            $result[] = $link;
        }
        return $result;
    }
    add_filter( "term_links-post_tag", 'mytheme_filter_tags', 100, 1 );
    			 echo get_the_tag_list('&lt;div class="entry"&gt;&lt;h4&gt; ',', ','&lt;/h4&gt;&lt;/div&gt;');
    			echo '&lt;/div&gt;';
    			remove_filter( "term_links-post_tag", 'mytheme_filter_tags', 100 );
    	}
    //HERE IS THE PART I AM HAVING TROUBLE WITH
    $posts = get_field('you_might_also_like'); 
    if( $posts ): 
    
    		foreach( $posts as $post): // variable must be called $post (IMPORTANT)
    		setup_postdata($post); ?&gt;
           &lt;div class="block"&gt;
    	    			    		
            						&lt;div class="fix"&gt;&lt;/div&gt;
            						&lt;h2 class="cufon"&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;
            						&lt;?php the_excerpt(); ?&gt;
            						&lt;span class="more"&gt;<a>"&gt;&lt;?php _e('More Info', 'woothemes') ?&gt;</a>&lt;/span&gt;
            					&lt;/div&gt;
    	&lt;?php endforeach; ?&gt;
        &lt;div class="fix"&gt;&lt;/div&gt;
    	&lt;?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
     endif; 
    
    
    }
    
    

    The site is password protected. User is demo, password is 12cce8

    http://etb.wpengine.com/speakers/alex-grey-2/
    November 12, 2016 at 9:57 pm #196081
    Brad Dalton
    Participant

    Hard to test because it relies on a 3rd party plugin setup as well as setup of multiple CPT's.

    I suggest you paste the code into a Github Gist and link to it.


    Tutorials for StudioPress Themes.

    November 14, 2016 at 9:43 am #196136
    agelfand
    Member

    Well, can anyone speak to the general issue of having secondary loop queries in genesis? It's frustrating that this widely used plugin doesn't have much in the way of documentation for use with Genesis. I would have guess the two are widely used together. Of course, I've been wrong before! 🙂

    https://gist.github.com/anonymous/232ad6bebf6b3a1b3e6c2e5093e1be95

    November 15, 2016 at 1:57 pm #196193
    agelfand
    Member

    Hi, it's me again. 🙂

    I placed my ACF fields in a template, to see if things would work inside a custom loop I crreated. Everything works except the POST OBJECT at the end. Can someone at least look at my code and see if there is an obvious fumble on my part? As with my custom function in functions.php, even though the $posts array with my custom data is in there, I can't get it to echo out. It just runs through however many post objects there are and echoes the title of the current post. This is a "you may also like" section.

    remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop
    add_action( 'genesis_loop', 'custom_do_loop' ); // Add custom loop
    
    function custom_do_loop() {  
      	
    while(have_posts()) : the_post();
    	// Intro Text (from page content)
    	echo '&lt;div class="page hentry entry"&gt;';
    	echo '&lt;h1 class="entry-title"&gt;'. the_title() .'&lt;/h1&gt;';
    	echo '&lt;div class="entry-content"&gt;' . the_content() .'&lt;/div&gt;';
    
    	
    	
    	$bookinglink = get_field('booking_url');
    	 echo '<a href="'.$bookinglink.'">';
    					$btntext = get_field('booking_button_text');
    					if ($btntext == '') { 
    					echo 'Book ';
    				echo the_title();
    					} else  {
    				echo $btntext; }
    				echo '</a>'; 
    				
    
                    
    		$video1 = get_field( 'video_one');
    		if( isset($video1) &amp;&amp; $video1 != '' ){
    		  echo '&lt;h4&gt;Video Gallery&lt;/h4&gt;';
    	  echo '&lt;div class="one-third first"&gt;';
    	  
    	  echo $video1;
        echo '&lt;/div&gt;';
    		}
    	 $video2 = get_field( 'video_two');
    	 if( isset($video2) &amp;&amp; $video2 != '' ){
    	 echo '&lt;div class="one-third"&gt;';
    	  $video2 = get_field( 'video_two');
    	  echo $video2;
        echo '&lt;/div&gt;';	
    	 }
    	  $video3 = get_field( 'video_three');
    	  if( isset($video3) &amp;&amp; $video3 != '' ){
    	 echo '&lt;div class="one-third"&gt;';
    	  $video3 = get_field( 'video_three');
    	  echo $video3;
        echo '&lt;/div&gt;';
    	  }
    	  echo '&lt;div class="clear"&gt;&lt;/div&gt;';	
    		$gallery_id = get_field('nextgen_gallery_id');
    		if( isset($gallery_id) &amp;&amp; $gallery_id != '' ){
    	  echo '&lt;h4&gt;Image Gallery&lt;/h4&gt;';
        echo "&lt;div class=\"post-gallery\"&gt;";
       //  echo nggShowGallery( $gallery_id ); // Display the gallery
      echo do_shortcode( $gallery_id );
        echo "&lt;/div&gt;&lt;div class='clear'&gt;&lt;/div&gt;";
      }
    	echo '&lt;div class="post"&gt;&lt;h4&gt;Topics&lt;/h4&gt;';
    	//HERE IS THE PART I AM HAVING TROUBLE WITH
    	
    	// always good to see exactly what you are working with
    
    $posts = get_field('you_might_also_like'); 
    // always good to see exactly what you are working with
    
    if( $posts ): 
    
    		foreach( $posts as $post): // variable must be called $post (IMPORTANT)
    		setup_postdata($post); ?&gt;
           &lt;div class="block"&gt;
    	    			    		
            						&lt;div class="fix"&gt;&lt;/div&gt;
            						&lt;h2 class="cufon"&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;
            						&lt;?php the_excerpt(); ?&gt;
            						&lt;span class="more"&gt;<a>"&gt;&lt;?php _e('More Info', 'woothemes') ?&gt;</a>&lt;/span&gt;
            					&lt;/div&gt;
    	&lt;?php endforeach; ?&gt;
        &lt;div class="fix"&gt;&lt;/div&gt;
    	&lt;?php  wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
     endif; 	
    
    endwhile;
    
    	
    	echo '&lt;/div&gt;&lt;!-- end .entry-content --&gt;';
    	echo '&lt;/div&gt;&lt;!-- end .page .hentry .entry --&gt;';
    }
    	
    /** Remove Post Info */
    remove_action('genesis_before_post_content','genesis_post_info');
    remove_action('genesis_after_post_content','genesis_post_meta');
     
    genesis();
    
    November 15, 2016 at 3:50 pm #196207
    agelfand
    Member

    The plot thickens! I moved the Post Object code outside the main loop. NOW I see the actual post objects selected in the back end through ACF, but they aren't being outputted in the page where I want them. Still, making progress. Can someone please help me along here? I need this post object to echo code before the end of the entry content...thank you.

    <?php
    
    remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop
    add_action( 'genesis_loop', 'custom_do_loop' ); // Add custom loop
    
    function custom_do_loop() {  
      	
    while(have_posts()) : the_post();
    	// Intro Text (from page content)
    	echo '<div class="page hentry entry">';
    	echo '<h1 class="entry-title">'. the_title() .'</h1>';
    	echo '<div class="entry-content">' . the_content() .'</div>';
    
    	
    	
    	$bookinglink = get_field('booking_url');
    	 echo '<a class="button" href="'.$bookinglink.'" >';
    					$btntext = get_field('booking_button_text');
    					if ($btntext == '') { 
    					echo 'Book ';
    				echo the_title();
    					} else  {
    				echo $btntext; }
    				echo '</a>'; 
    				
    
                    
    		$video1 = get_field( 'video_one');
    		if( isset($video1) && $video1 != '' ){
    		  echo '<h4>Video Gallery</h4>';
    	  echo '<div class="one-third first">';
    	  
    	  echo $video1;
        echo '</div>';
    		}
    	 $video2 = get_field( 'video_two');
    	 if( isset($video2) && $video2 != '' ){
    	 echo '<div class="one-third">';
    	  $video2 = get_field( 'video_two');
    	  echo $video2;
        echo '</div>';	
    	 }
    	  $video3 = get_field( 'video_three');
    	  if( isset($video3) && $video3 != '' ){
    	 echo '<div class="one-third">';
    	  $video3 = get_field( 'video_three');
    	  echo $video3;
        echo '</div>';
    	  }
    	  echo '<div class="clear"></div>';	
    		$gallery_id = get_field('nextgen_gallery_id');
    		if( isset($gallery_id) && $gallery_id != '' ){
    	  echo '<h4>Image Gallery</h4>';
        echo "<div class=\"post-gallery\">";
       //  echo nggShowGallery( $gallery_id ); // Display the gallery
      echo do_shortcode( $gallery_id );
        echo "</div><div class='clear'></div>";
      }
    	echo '<div class="post"><h4>Topics</h4>';
    	
    endwhile;
    
    }
    //HERE IS THE PART I AM HAVING TROUBLE WITH
    	
    	// always good to see exactly what you are working with
    
    $posts = get_field('you_might_also_like'); 
    // always good to see exactly what you are working with
    
    if( $posts ): 
    
    		foreach( $posts as $post): // variable must be called $post (IMPORTANT)
    		setup_postdata($post); ?>
           <div class="block">
    	    			    		
            						<div class="fix"></div>
            						<h2 class="cufon"><?php the_title(); ?></h2>
            						<?php the_excerpt(); ?>
            						<span class="more"><a href="<?php the_permalink(); ?>"><?php _e('More Info', 'woothemes') ?></a></span>
            					</div>
    	<?php endforeach; ?>
        <div class="fix"></div>
    	<?php  wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
     endif; 
    	
    	
    
    echo '</div><!-- end .entry-content -->';
    	echo '</div><!-- end .page .hentry .entry -->';
    	
    /** Remove Post Info */
    remove_action('genesis_before_post_content','genesis_post_info');
    remove_action('genesis_after_post_content','genesis_post_meta');
     
    genesis();
  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble