Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Forked from thagxt/recently-updated-feed.php
Last active February 1, 2019 16:53
Show Gist options
  • Save Alexander-Pop/8f67fd4507beb1e2ab2a420fe30ca9e4 to your computer and use it in GitHub Desktop.
Save Alexander-Pop/8f67fd4507beb1e2ab2a420fe30ca9e4 to your computer and use it in GitHub Desktop.
Custom RSS feed for WordPress with the latest updated posts. #feed #wp
<?php
/**
* Template Name: RSS - Recently Updated
*/
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'modified',
'order' => 'DESC',
'ignore_sticky_posts' => '1',
'caller_get_posts' => 1
);
$updated = new WP_Query($args);
header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
<?php do_action('rss2_ns'); ?>>
<channel>
<title><?php bloginfo_rss('name'); ?> - Recently Updated Feed</title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss('url') ?></link>
<description><?php bloginfo_rss('description') ?></description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('blog'), false); ?></lastBuildDate>
<language>en-US</language>
<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
<?php do_action('rss2_head'); ?>
<?php
while($updated->have_posts()) : $updated->the_post();
$product_img = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $isize );
$getImg = $product_img[0];
$today = current_time('Y-m-d');
$pub = get_the_time('Y-m-d', $updated->ID);
$mod = get_the_modified_time('Y-m-d', $updated->ID);
$modIFTTT = get_the_modified_time('D, d M Y H:i:s +0000', $updated->ID);
if ( $pub !== $today && $mod === $today ) :
?>
<item>
<title><?php the_title_rss(); ?></title>
<link><?php the_permalink_rss(); ?></link>
<pubDate><?php echo $modIFTTT; ?></pubDate>
<dc:creator><?php the_author(); ?></dc:creator>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<description><![CDATA[<img src="<?php echo $getImg; ?>" width="250"><br> <?php the_excerpt_rss() ?>]]></description>
<content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
<?php rss_enclosure(); ?>
<?php do_action('rss2_item'); ?>
</item>
<?php endif; endwhile; ?>
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment