admin管理员组文章数量:1428474
How to disable lastBuildDate
for rss feed and include only the posts created recently (ex. 3 days before now)?
If there is no post, let the feed be empty. I wants to show only recent posts in rss feed.
How to disable lastBuildDate
for rss feed and include only the posts created recently (ex. 3 days before now)?
If there is no post, let the feed be empty. I wants to show only recent posts in rss feed.
Share Improve this question edited Apr 20, 2019 at 17:28 Fayaz 9,0172 gold badges33 silver badges51 bronze badges asked Apr 20, 2019 at 13:44 Robert ZalinyanRobert Zalinyan 191 bronze badge 2- 2 Hi, welcome to WPSE. Did you try anything? If so, then please edit the question and add the CODE you've tried so far. – Fayaz Commented Apr 20, 2019 at 17:29
- I did not write any code so far. Is there any wp function that do the rss post query in rss feed? – Robert Zalinyan Commented May 3, 2019 at 20:24
1 Answer
Reset to default 1Removing lastBuildDate
:
lastBuildDate
should not be removed from the rss feed, it may cause rss feed validation error/warning.
However, it's possible to filter the date using get_lastpostmodified
filter hook.
Filtering feed content listing:
The rules for filtering feed
content listing is the same as the rules for filtering any content listing in WordPress, the only difference is that you'll have to use the WP_Query::is_feed check.
So in most cases, you'll have to use WP_Query
accompanied by pre_get_posts
action hook and then use the CODE in a custom plugin or in the theme's functions.php
file.
Also, to filter the date, you may use the date_query
.
Example CODE:
The CODE below lists only the posts from 3 days before now in the feed and gives an option to modify the value of lastBuildDate
(as you've asked in the question).
function wpse334869_lastBuildDate( $lastpostmodified ) {
// if you need, modify the $lastpostmodified here, before returning it
return $lastpostmodified;
}
function wpse334869_filter_feed( $query ) {
if( $query->is_feed() ) {
add_filter( 'get_lastpostmodified', 'wpse334869_lastBuildDate');
$query->set( 'date_query', array(
array(
'after' => '3 days ago'
)
) );
}
}
add_action( 'pre_get_posts', 'wpse334869_filter_feed' );
Note: This is just a sample concept CODE, so make sure you test it before using it on a live site.
Further Reading:
- Customizing Feeds.
- Acceptable Date Strings.
本文标签: Include only recents custom posts in WP rss feed
版权声明:本文标题:Include only recents custom posts in WP rss feed 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745524820a2661787.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论