Support

Account

Home Forums Add-ons Repeater Field Post Object Custom Field

Solved

Post Object Custom Field

  • Could someone please help me? I am trying to call into my page informationing from a repeating field’s sub field and keep gettingteh error:

    Post Object Custom Field:
    Catchable fatal error: Object of class WP_Post could not be converted to string in /home/elmwood1/public_html/wdpr/wp-content/plugins/advanced-custom-fields-pro/api/api-template.php on line 911

    As far as I know I am using the code correctly as provided in your FAQ section.

  • Hi @elmwoodplayhouse

    I can’t help you without more information. Could you please post the code you’re using and perhaps do a screenshot of what your repeater field with subfields looks like.

  • This reply has been marked as private.
  • Hi Jonathan, just wanted to me the file I sent thru with answers to your question me thru (I think it did but Im not 100% sure) thanks!

  • Hi @elmwoodplayhouse

    You could just post the code here as well within code tags tho 🙂

    Try this:

    
    <?php if( have_rows('cast') ): ?>
    
    	<?php while( have_rows('cast') ): the_row(); ?>
    
    		<?php $post_object = get_sub_field('actor'); ?>
    	    <?php if( $post_object ): ?>
    			<?php
    	        // override $post
    	        $post = $post_object;
    	        setup_postdata( $post );
    			?>
                  
    			<h1><?php the_title(); ?></h1>
    
    			<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    
            <?php endif; ?>
    	<?php endwhile; ?>
    
    <?php endif; ?>
    
  • Great! That works! Thanks you made my otherwise crappy day and a little brighter (actually things are good so I shouldnt complain) It was driving me crazy. Wish I knew what I was doing wrong. But now that I have your code which is correct, I can examine it more closely for myself. Thanks again!

  • No problem, glad I could help you out and maybe brighten your day a little 😉

    Your code wasn’t really that much wrong I think you were just confused over how the post data setup works.

    you fetched the artist post object with get_sub_field but then attempted to echo out the very same post object inside the setup_postdata instead of using WP core functions such as the_title(); the_content() etc.

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

The topic ‘Post Object Custom Field’ is closed to new replies.