Adam
Adam

Reputation: 832

Advanced custom fields - pulling data in from another page

Hello I am using advanced custom fields and I am trying to pull data from multiple pages and display it on another

I set up a relationship field called "data", and then on page X where the relationship field is displayed I have chosen page Y where I want to pull the data from

<?php if( get_field('data') ): ?>
     <?php the_field('special_offer'); ?> <!--// get content from page Y -->
<?php endif; ?>

I can't get this to work though and Im presuming the above is wrong, does anyone know how I could do this please?

Hopefully I have explained it clearly

Cheers

*This seems to be the solution, although having troubles pulling the_content etc

  <?php  $offers = get_field('data'); ?>

    <?php if( $offers ): ?>
        <ul>
        <?php foreach( $offers as $location ): ?>
            <li>
                <a href="<?php echo get_permalink( $location->ID ); ?>">
                    <?php echo get_the_title( $location->ID ); ?>
                </a>
            </li>
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>

Upvotes: 1

Views: 7320

Answers (1)

Kate
Kate

Reputation: 31

You have to include the page ID in the code:

<?php if( get_field('data', 123) ): ?>
<?php the_field('special_offer', 123); ?> <!--// get content from page Y -->
<?php endif; ?>

From the documentation: http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-another-page/

Upvotes: 3

Related Questions