[resolved] the_date() problem after get_posts() (3 posts)

  1. lupinek
    Posted 6 years ago #

    I use custom template for one page and I recently encountered a little problem with the_date(). $cat[0] is a string containing name of the category.

    $myposts = get_posts('numberposts=-1&category_name='."$cat[0]".'&orderby=date&post_status=&offset=1');
    	foreach($myposts as $post)
    		echo $post->post_date;

    the_title gives right output - title. Permalink also shows up, but the_date() gives no result for one post - it works fine for all others. It's even more interesting that $post->post_date contains correct data for this post.
    At the moment I “hacked” this and I use date('Y-m-d', strtotime($post->post_date)) which gives expected results, but still there's something wrong either with my code (??) or with the_date() function.

  2. Rev. Voodoo
    Posted 6 years ago #

    the_date only outputs once per date.... so if you have more than one post on that date, nothing will output

    using the_time (with date formatting) works for multiple posts per date

  3. lupinek
    Posted 6 years ago #

    How is it possible that I haven't seen the big warning in codex? o.O
    Problem solved, sorry for my stupidity.

Topic Closed

This topic has been closed to new replies.

About this Topic