0

I would like to get a list of the posts published in WP in every category with the published date and the last modified date.

I've tried to achieve this result through a Plugin but it's completely not mature. So I am also ready to write some code.

I've googled and found this link wp_get_recent_posts

<?php $args = array(
    'numberposts' => 10,
    'offset' => 0,
    'category' => 0,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'include' => ,
    'exclude' => ,
    'meta_key' => ,
    'meta_value' =>,
    'post_type' => 'post',
    'post_status' => 'draft, publish, future, pending, private',
    'suppress_filters' => true );

    $recent_posts = wp_get_recent_posts( $args, ARRAY_A );
?>

But a big question is where can I put this code and how to get the date? Should I create a micro plugin?

  • 1
    Do you mean, you like posts, status draft about all categories in a time window of his published date? Or you will get the published and modified date from the post, after you have the post. At first you get a list of post, then have each post this data. You get this via additional function. – bueltge Apr 2 '15 at 8:02
  • @bueltge: and which is the name of the additional function? – Revious Apr 2 '15 at 8:25
  • See the answer much more whitespace for a solid return. – bueltge Apr 6 '15 at 12:30
1

Which wp_get_recent_posts()do you retrieve the most recent posts. For meta data, like published date and modified date use additional functions.

For the published date is the_date() helpful.

For the modified date use the_modified_date().

The functions are a part of the Template Tags, useful for Theme and direct output. But she have also parameters to get the values for custom echo.

A small example:

<h2>Recent Posts</h2>
<ul>
<?php
    $args = array( 'numberposts' => '5' );
    $recent_posts = wp_get_recent_posts( $args );

    foreach( $recent_posts as $recent ){

        echo '<li><a href="' . get_permalink($recent["ID"]) 
             . '">' .   $recent["post_title"] 
             . '</a> Published on ' 
             . the_date( $echo = FALSE ) 
             . ', Modified on ' 
             . the_modified_date( $echo = FALSE ) 
             . '</li> ';
    }
?>
</ul>

The example is not ready to use, especially translation ready. Enhance with the i18n functions from WordPress to create a solid, translatable and sanitized result with the helper functions for this topic, like esc_attr_e(), esc_attr__() and printf().

If you don't like to use the parameters on the functions, more short. Then use the functions, there was used inside the Template Tags - get_the_modified_date() and get_the_date().

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.