WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
[Advanced Custom Fields] Post Object (5 posts)

  1. royromviel
    Member
    Posted 2 years ago #

    I have a problem with the Post Object option.

    Here is the thing. I have a custom posttype named Testimonials. That custom post type contains a excerpt.

    No i have some pages that need the excerpts of some Testimonials pages.
    So i use the advanced custom field option Post Object.
    In my page template I use the example from the site:

    <ul>
    <?php foreach(get_field('post_object') as $post_object): ?>
        <li><a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID) ?></a></li>
    <?php endforeach; ?>
    </ul>

    But when i check the page the page is giving me the permalink's and the titles of the page im already on it. It makes a list of 25 items with the same.

    Example: http://www.trustpayrolling.nl/wordpress/onze-klanten/

    What do i do wrong?

    Here is the full code of the page:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  2. royromviel
    Member
    Posted 2 years ago #

    C'mon... Nobody can answer my question?

  3. mhuntdesign
    Member
    Posted 2 years ago #

    royromviel, Make sure you are using the foreach code snippet on the page template that corresponds with the page that you are making the selections. Use the relationship field if possible instead of the post object field in ACF. They are the same, but there is a better interface for relationship. Then, if you want to display the excerpt or content you will need to hook into the post type object attributes. Here is a reference: http://www.sagalbot.com/blog/wordpress-post-object-reference/

    So to display the excerpts you need to do this:

    <ul>
    <?php foreach(get_field('post_object') as $post_object): ?>
        <li><a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID) ?></a> <p><?php print $post_object->post_excerpt; ?></p> </li>
    <?php endforeach; ?>
    </ul>

    See how I have placed <?php print $post_object->post_excerpt; ?>

    Let me know how it goes. Looks like it's been a few weeks and you may have already moved on.

  4. royromviel
    Member
    Posted 2 years ago #

    Hey mhuntdesign,

    Tnx for the reply. I will go into this soon. I will let you know how it went.

  5. alturnwall
    Member
    Posted 2 years ago #

    Same question, and that worked for me, thank you mhuntdesign!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic