Custom post types – RSS lastBuildDate issue

The question:

I’m using CMS Press for custom post types. The issue is the feed doesn’t validate because lastBuildDate is blank. I am not using WordPress’s default posts for anything and that is causing the problem.

I did a test post using WordPress’s default post and voila lastBuildDate was filled in and the feed validated.

As soon as I deleted the post it removed the date in lastBuildDate and the feed didn’t validate.

I’m using the code below to add the custom post types in the main feed but this is an issue with the feeds created by the custom post types also.

Am I missing something to get the lastBuildDate to populate?

if ( ( is_front_page() && false == $query->query_vars['suppress_filters'] ) || is_feed() ){
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        query_posts( array('post_type'=>array('post', 'games', 'entertainment', 'tech', 'podcasts'),'paged'=>$paged ) );

I answered my own question below.

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

This is the solution I found based off of @Rarst’s answer. Put this in the themes functions.php and it worked like a charm!

add_filter('get_lastpostmodified', 'my_lastpostmodified');
function my_lastpostmodified()
    global $wpdb;
    $add_seconds_server = date('Z');
    return $wpdb->get_var("SELECT  DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' ORDER  BY post_modified_gmt DESC LIMIT 1");

Method 2

Use WordPress functionality

The function get_lastpostmodified() is extensively documented. It says in the wordpress documentation that the function accepts a timezone and a post_type.


From WordPress Trac: wp-includes/post.php1

5355     * @param string $post_type Optional. The post type to check. Default 'any'.
5356     * @return string The timestamp.
5357     */
5358    function get_lastpostmodified( $timezone = 'server', $post_type = 'any' ) {


If you want to check for the last post modified of a certain post type (let’s say ‘GAMES’). You would call the function as follows:

get_lastpostmodified('GMT', 'Games');

Following with an example of my custom feed meant for a popular job site. Here I use a Custom Post Type (CPT) called ‘JOB’:

// ...
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT', 'job'), false); ?> GMT</lastBuildDate><pre>
// ...



Method 3

lastBuildDate is getting filled with data returned by get_lastpostmodified() function. Which only checks for native post type, so if you have none – there is no date found.

Filter get_lastpostmodified hook to return some other build date (in MySQL DATETIME format) instead of it.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment