Home › Forums › Add-ons › Repeater Field › 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.
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.
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!
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.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.