KodeFor.Me
KodeFor.Me

Reputation: 13511

WordPress | Date not always appear

I try to create a theme. In that theme I have create a custom post type and I quering the WordPress by using the wp_query to get the posts from that post type with the code that following :

$args = array(
    'post_type'         =>  'portfolio',
    'posts_per_page'    =>  18
);

$projects = new WP_Query($args);

while($projects->have_posts())
{
    $projects->the_post();
?>
<h3><?php the_title(); ?></h3>
<span><?php the_date(); ?></span>
<?php
}

wp_reset_postdata();

the problem is, that while I get the title for all of my posts, I do not get the date for all of my posts. Some posts have the date, other they don't

Any idea for that issue ?

Upvotes: 0

Views: 42

Answers (1)

Tom Walters
Tom Walters

Reputation: 15616

Replace the_date() with the_time() and specify a date format like so:

the_time('l, F j, Y');

Check out the codex article on formatting your date.

Upvotes: 1

Related Questions