index.php

RSS Feed to WordPress Post Plugin

The 'RSS Feed to WP Post' plugin is a WordPress plugin that automatically fetches items from a specified RSS feed and creates WordPress posts for each unique item. It allows for setting post type, status, and import limits, and runs on an hourly schedule to check for new content.

<?php /* Plugin Name: RSS Feed to WP Post Plugin URI: https://codewp.ai Description: This plugin automatically creates and publishes posts on WordPress from an RSS feed. Version: 1.0 Author: CodeWP Assistant Author URI: https://codewp.ai Text Domain: codewp */ define('RSS_FEED_URL', 'http://example.com/rss'); // Replace with your RSS feed URL define('POST_TYPE', 'post'); // Set the post type define('POST_STATUS', 'publish'); // Set the post status define('IMPORT_LIMIT', 10); // Maximum number of posts to import. Set to 0 for unlimited. function codewp_fetch_rss_feed() { $feed = fetch_feed(RSS_FEED_URL); if (!is_wp_error($feed)) { $items = $feed->get_items(); $import_count = 0; foreach ($items as $item) { if (IMPORT_LIMIT > 0 && $import_count >= IMPORT_LIMIT) { break; } $post_id = post_exists($item->get_title()); if (!$post_id) { $post_data = array( 'post_title' => wp_strip_all_tags($item->get_title()), 'post_content' => $item->get_content(), 'post_status' => POST_STATUS, 'post_type' => POST_TYPE, ); wp_insert_post($post_data); $import_count++; } } } } if (!wp_next_scheduled('codewp_fetch_rss_feed')) { wp_schedule_event(time(), 'hourly', 'codewp_fetch_rss_feed'); } add_action('codewp_fetch_rss_feed', 'codewp_fetch_rss_feed');

Frequently Asked Questions

This plugin is designed to automatically import posts from an RSS feed and publish them on a WordPress site.