Support

Account

Home Forums Front-end Issues Display data for multiple post objects

Solved

Display data for multiple post objects

  • I’m trying to make use of the Post Object field, whereby I’d like select multiple posts (Portfolio pages) and print into a page the URL to these pages.

    on the backend I’ve configured the following: https://goo.gl/mROoUq

    but just can’t get the following supplied example code to work:

    <?php

    /*
    * Loop through post objects (assuming this is a multi-select field) ( setup postdata )
    * Using this method, you can use all the normal WP functions as the $post object is temporarily initialized within the loop
    * Read more: http://codex.wordpress.org/Template_Tags/get_posts#Reset_after_Postlists_with_offset
    */

    $post_objects = get_field(‘post_objects’);

    if( $post_objects ): ?>

      <?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
      <?php setup_postdata($post); ?>

    • “><?php the_title(); ?>
      <span>Post Object Custom Field: <?php the_field(‘field_name’); ?></span>
    • <?php endforeach; ?>

    <?php wp_reset_postdata(); // IMPORTANT – reset the $post object so the rest of the page works correctly ?>
    <?php endif;

    What am I doing wrong – can someone help me please?

    thanks – using 5.0.3 on WP 4.3

  • From your screenshot, it looks like you’re using a “Page Link” field type, not a “Post Object” field type.

  • The previous reply is correct. The page link field only returns the url of the page. To use the example you posted you need to use a Post Object or Relationship type field.

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

The topic ‘Display data for multiple post objects’ is closed to new replies.