Support

Account

Home Forums Front-end Issues Display Post Date in Relationship Feild

Helping

Display Post Date in Relationship Feild

  • Hi i Am using the relationship field and on the front end i am trying to display the post date how do i do this? i tried a few things but i just get today’s date.

    Thanks Matt

    				<?php $posts = get_field('related_posts'); if( $posts ): ?>
    					<?php foreach( $posts as $post_object): ?>
    					    <article class="post" role="article">
    					    		<header class="entry-header">
    					    			<div class="post-thumb">
    					    				<a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_post_thumbnail($post_object->ID); ?></a>
    					    			</div>
    									<span class="entry-title-blog">
    										<a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID); ?></a>
    									</span>
    									<div class="post-date">
    										<?php echo get_the_date('F j, Y');?>
    									</div><!-- .entry-meta -->
    					    		<header>
    								<div class="entry-content">
    									<?php echo get_the_excerpt($post_object->ID); ?>
    								</div>							
    					    </article>
    					<?php endforeach; ?>
    				<?php endif;?>
  • Hi @weareempire

    In the same way that you pass $post_object->ID to the get_permalink function, you need to pass this to the get_the_date function too.

    That said, the get_date function doesn’t have a parameter for $post_id, so you will need to use get_the_time instead:
    http://codex.wordpress.org/Function_Reference/get_the_time

    Thanks
    E

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

The topic ‘Display Post Date in Relationship Feild’ is closed to new replies.