get_posts date not working

Discussion in 'WordPress' started by sixrfan, Feb 28, 2011.

  1. #1
    on this page i have the code below to pull in the two most recent posts. however for some reason, the date it says below the title is January 20, 2011 for both posts event though they both have two different "Published Dates" than that.

    why's this happening???

    <h2>The Latest at Cornerstone</h2>
    
    <?php
    $latestposts = get_posts('numberposts=2&category=1');
    foreach($latestposts as $post) :
       setup_postdata($post);
    ?>
    <h3><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></h3>
    <h6><?php the_date(); ?></h6>
    <?php the_content(); ?>
    <?php endforeach; ?>
    
    PHP:
     
    sixrfan, Feb 28, 2011 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not sure, the_date() has a strange rule about only being used once.
    Try using <?php the_time('F j, Y'); ?>, or try <?php echo get_the_date(); ?> if that does not work.
     
    Cash Nebula, Mar 1, 2011 IP
  3. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    thanks but that did not work. it still replicated January 20th on both. any other suggestions?
     
    sixrfan, Mar 1, 2011 IP
  4. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #4
    this seems to be working, though the post titles have now disappeard:
    
    <?php
    $custom_query = new WP_Query( 'posts_per_page=2&cat=1' );
    if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
    
      <h3><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></h3>
      <h6><?php the_time('F j, Y') ?></h6>
      <?php the_content(); ?>
      
    <?php endwhile; else : ?>
    
      <h3>Sorry...</h3>
      <p>No posts were found.</p>
      
    <?php endif; ?>
    
    Code (markup):
    any idea how to get these post titles, which you can see here, to show??
     
    Last edited: Mar 1, 2011
    sixrfan, Mar 1, 2011 IP
  5. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    actually this seems to be working:
    
    <?php
    $custom_query = new WP_Query( 'posts_per_page=2&cat=1' );
    if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
    
      <h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </h3>
      <h6><?php the_time('F j, Y') ?></h6>
      <?php the_content(); ?>
      
    <?php endwhile; else : ?>
    
      <h3>Sorry...</h3>
      <p>No posts were found.</p>
      
    <?php endif; ?>
    
    Code (markup):
     
    sixrfan, Mar 1, 2011 IP