• sarscott

    (@sarscott)


    This is probably a simple one but I can’t seem to find an answer anywhere.

    I have 2 custom post types. I display them in sections on my home page.

    In each section I’d like to have “Last Updated [DATE]” text near the title for each section.

    I’ve found <?php get_lastpostdate( $timezone ) ?> but is there a way of specifying which post type you’d like to query?

    Many thanks,

    S

Viewing 1 replies (of 1 total)
  • Thread Starter sarscott

    (@sarscott)

    Well, I got an answer over at Stackoverflow. Look like I have to query the post type, get the last post and get it’s modified date. I then wanted to format the date so that it read like “15th May”.

    The code is as follows.

    <p><?php
        $latest = new WP_Query(array('post_type' => 'car', 'post_status' => 'publish', 'posts_per_page' => 1, 'orderby' => 'modified', 'order' => 'ASC'));
        if($latest->have_posts()){
            $modified_date = $latest->posts[0]->post_modified;
        }
        //Get the last post update and display the date as "10th March"
        $lastpost = strtotime($modified_date);
        $lastmonth = date('F', $lastpost);
        $lastday = date('jS', $lastpost);
        echo 'Last Updated '.$lastday.' '.$lastmonth;
        ?>
    </p>
Viewing 1 replies (of 1 total)

The topic ‘get_lastpostdate for custom post type’ is closed to new replies.