Home Forums WordPress Website how can I retrieve all posts that was created after a specific post

This topic contains 1 reply, has 2 voices, and was last updated by  WPsitex 1 year, 2 months ago.

  • Author
  • #269

    Rajesh Singh

    I am working on a blogging website. I need a function that I can send a mail to all my subscriber with information about the blog posts made in the current month only. Is there any function to workout the same.

  • #1100


    You can work is out in 2 ways –

    1. Use the following code with post meta of that specific post –

     $querystr = "
        SELECT $wpdb->posts.* 
        FROM $wpdb->posts, $wpdb->postmeta
        WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id 
        AND $wpdb->posts.post_status = 'publish' 
        AND $wpdb->posts.post_type = 'post'
        AND $wpdb->posts.post_date > datepost
        ORDER BY $wpdb->posts.post_date DESC
     $pageposts = $wpdb->get_results($querystr, OBJECT);

    2. Use the following code if you want to use the timestamp with after parameter –

    $post_date = get_the_date('H-i-s-m-d-Y', $last_post_id);
    $units = explode('-', $post_date);
    $timestamp = mktime($units[0], $units[1], $units[2], $units[3], $units[4], $units[5]);
    $args = array(
        'date_query' => array(
            'after' => date('c', $timestamp)
        'posts_per_page' => -1

    Above codes are to be putup in the function.php file.

    • This reply was modified 1 year, 2 months ago by  WPsitex.
    • This reply was modified 1 year, 2 months ago by  WPsitex.

You must be logged in to reply to this topic.

Close Menu