• Hi,

    The default RSS widget displays published date, but I want it to display the udpated date of the feed items.

    I am assuming that the right place from where the published date is picked from feed-rss2 file

    <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>

    Is it sufficient if I updated get_post_time to get_the_modified_time?

    <pubDate><?php echo mysql2date('r', get_the_modified_date('Y-m-d H:i:s')); ?></pubDate>

    Please clarify.

Viewing 12 replies - 1 through 12 (of 12 total)
  • I believe you got that right. You need the posts modified date. As the Codex explains https://codex.wordpress.org/Function_Reference/get_the_modified_date this is the correct function to do that.

    Do you know exactly which WordPress action to hook on in order to filter your RSS the way you want to?

    Thread Starter WPUser_NY

    (@wpuser_ny)

    In feed-rss2 file,

    <item>
     <title><?php the_title_rss() ?></title>
     <link><?php the_permalink_rss() ?></link>
     <comments><?php comments_link_feed(); ?></comments>
     <pubDate><?php echo mysql2date('r', get_the_modified_date('Y-m-d H:i:s')); ?></pubDate>
     <dc:creator><![CDATA[<?php the_author() ?>]]></dc:creator>
     <?php the_category_rss('rss2') ?>

    I replaced get_post_date with get_the_modified_date, but still the feed is showing posted date.

    Do I need to update any other instances of get_post_date in other files as well or if there’s a way around to display the updated date of the post?

    Hmm, this should suffice. Are you sure you are not seeing some older version of the rss through a feed reader or some cached version of it?

    Thread Starter WPUser_NY

    (@wpuser_ny)

    Yeah, i am looking at the actual feed that’s pulled from source, so its not cached. It displays the published date, and not the updated date.

    Would it be possible to use firebug or some such tool to look at the DOM structure that’s pulled when the feed is generated? or maybe trace which files are being invoked for populating the rss section?

    The RSS feed is a simple XML text, so all you need to do is look at its source and it will all be there!

    Is it possobile that you are looking at a cached version?

    What program do you use to check you feed?

    Thread Starter WPUser_NY

    (@wpuser_ny)

    I am using a default RSS widget in Wordpres, and supplying a source url.

    When I check the source of RSS, it contains both a published date and updated date, but the RSS widget is picking the published date rather than the updated date.

    Forgive me for mentioning this one last time, but these widgets ususally cache their results for some period of time in order to avoid connecting to the source url all the time. So, just one last check that these results are actually not cached by the plugin?

    Also, is it possible that the file that controls your feed is not feed-rss2.php but one of the other feed PHP files?

    Last but not least, as I see inside feed-rss2.php, maybe it is better to change the ‘pubDate’ by hooking to the ‘rss2_item’ action. This action becomes simply ‘rss_item’ in feed-rss.php and so on.

    Thread Starter WPUser_NY

    (@wpuser_ny)

    That’s what I am thinking too is that probably feed-rss2.php may not be the file that’s invoked when the RSS is picking the data.

    But feed-rss2.php file is what is referenced in other posts too, though the posts were not specific to resolving this issue with updated date.

    Are you suggesting that this section be updated in feed-rss2.php to replace rss2_item mentioned in do_action(‘rss2_item’) with rss_item?
    Please clarify.

    <item>
    		<title><?php the_title_rss() ?></title>
    		<link><?php the_permalink_rss() ?></link>
    		<comments><?php comments_link_feed(); ?></comments>
    		<pubDate><?php echo mysql2date('r', get_the_modified_date('Y-m-d H:i:s')); ?></pubDate>
    		<dc:creator><![CDATA[<?php the_author() ?>]]></dc:creator>
    		<?php the_category_rss('rss2') ?>
    
    		<guid isPermaLink="false"><?php the_guid(); ?></guid>
    <?php if (get_option('rss_use_excerpt')) : ?>
    		<description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
    <?php else : ?>
    		<description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>
    	<?php $content = get_the_content_feed('rss2'); ?>
    	<?php if ( strlen( $content ) > 0 ) : ?>
    		<content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>
    	<?php else : ?>
    		<content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded>
    	<?php endif; ?>
    <?php endif; ?>
    		<wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2') ); ?></wfw:commentRss>
    		<slash:comments><?php echo get_comments_number(); ?></slash:comments>
    <?php rss_enclosure(); ?>
    	<?php
    	/**
    	 * Fires at the end of each RSS2 feed item.
    	 *
    	 * @since 2.0.0
    	 */
    	do_action( 'rss2_item' );
    	?>
    	</item>

    Can you please explain why you think that it might solve the issue?

    Sorry for not making this clear enough in the first place.

    What you need to check first of all is if the widget caches its content for a long time because this is what such widget usually do epecially when they connect to other services like RSS to get content.

    Apart from that, I suggested that is advised that one does not edit the file feed-rss2.php directly, but rather hook to the appropriate actions. In this case the appopriate action is ‘rss2_item’. So if you want to manipulate each RSS <item/> you should hook to this action and echo what you need to ovewrite any part of the item you need. However, this is a totally separate thing from the caching I explained above.

    Thread Starter WPUser_NY

    (@wpuser_ny)

    Thank you. I understood when you explained the cache part. However, we can rule out that this issue is related to cache because its the same even when i check from new browsers.

    Oh well this is a different kind of cache I am talking about. It is a server side cache not a browser cache. If really need to rule it out you must check it out on the server side probably in the transients in the options database table.

    Thread Starter WPUser_NY

    (@wpuser_ny)

    Thank you for the suggestion.

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Need help to display RSS Modified Date instead of Published Date’ is closed to new replies.