1

I am using Advanced Custom Fields using the Relationship field type and I am struggling to get the date of the post to come through.

https://www.advancedcustomfields.com/resources/relationship/

Here is my code:

<?php 

$posts = get_field('blha');

if( $posts ): ?>
<ul>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
    <li class="latest-stories-excerpt <?php echo (++$j % 2 == 0) ? 'evenpost' : 'oddpost'; ?>">

             <p class="front-latest-date"><span class="topic-selector"><?php if( get_post_field('topic_selector') ) echo get_post_field('topic_selector') . ','; ?></span>


            <span><?php echo get_the_date( $p->ID ); ?></span></p>


            <div class="latest-stories-thumb">
                <?php echo get_the_post_thumbnail( $p->ID, 'latest-two-stories' ); ?>
            </div>

            <h3 class="latest-stories-post"><a href="<?php echo get_permalink( $p->ID ); ?>" class="anImgNew">
                <?php echo get_the_title( $p->ID ); ?>
            </a></h3>




        <p><?php echo get_the_excerpt( $p->ID ); ?></p>




    </li>
<?php endforeach; ?>
</ul>

I've also tried this:

<?php $pfx_date = get_the_date( $format, $post_id ); ?>

And I have tried this too:

<?php $date = get_the_date('jS F Y', $p->ID); ?>

But nothing. I am lost at this point. I've ready all the ACF docs but nothing and have asked the ACF support forum and again nothing hence I am here to ask you!

Anyone have a idea?

Cheers

  • 1
    Have you tried echo get_the_date('jS F Y', $p->ID);? Note the echo. – Jacob Peattie Jun 5 '18 at 11:18
  • Hey Jacob - thanks for that. You have solved it. I think I tried that before but with the $p-ID at the front. I can not mark you answer as answer - would like the credit to go to you! – bob Jun 5 '18 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.