Support

Account

Home Forums Front-end Issues No output data from Post Object

Solved

No output data from Post Object

  • My blog page, home.php, calls content-single.php for each post.

    Content-single.php calls a function defined in functions.php to output data from a post object.

    When I debug by print_r’ing the post object, I see it return the post object as expected. However, no data is output from the fields within that post object, “team_member_name” for example:

    function myfunction() {
    
    	$post_object = get_field('post_author');
    
    	print_r($post_object); // OUTPUTS POST OBJECT
    		
    	if( $post_object ){
    		// override $post
    		$post = $post_object;
    		setup_postdata( $post ); 
    		the_field( 'team_member_name' ); // NO OUTPUT
        wp_reset_postdata();
    
      }
    }

    Here’s the post object as returned in print_r:

    WP_Post Object ( [ID] => 72 [post_author] => 1 [post_date] => 2014-11-19 19:28:13 [post_date_gmt] => 2014-11-19 19:28:13 [post_content] => [post_title] => Robin Glen [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => robin-glen [to_ping] => [pinged] => [post_modified] => 2015-01-07 16:00:55 [post_modified_gmt] => 2015-01-07 21:00:55 [post_content_filtered] => [post_parent] => 0 [guid] => http://www.example.com/?post_type=leadership-team&p=72 [menu_order] => 0 [post_type] => leadership-team [post_mime_type] => [comment_count] => 0 [filter] => raw )

  • By outputting the_title() I discovered I wasn’t in the loop I thought I was. I then realized I needed to add “global $post” in order to reference the global $post variable.

    I’m still sharpening my WordPress skills. Hope this helps someone else!

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

The topic ‘No output data from Post Object’ is closed to new replies.