F2P Filter: Set a Minimum Word Limit for Posts to be Imported
By default, Feed to Post imports all the available feed items from a feed source as posts.
However, sometimes you might want to prevent very short posts from being imported for some reason or another.
The below filter allows you to set a minimum number of words for imported posts, meaning that if a post has less than the set number of words, it will not be imported at all.
The number of words (80 in the example below) can be changed to any limit you want.
add_filter( 'wprss_ftp_post_args', 'my_custom_post_args', 10, 2 ); function my_custom_post_args( $post, $feed_source ) { $new_post = $post; $post_content_word_count = str_word_count( $new_post['post_content'] ); if( $post_content_word_count < 80 ){ return NULL; // return null if number of words are less than 80 } // Return the new post return $new_post; }
How do I add this to my site?
Follow the step-by-step instructions below to add this filter to your WordPress site.
- Copy the code you need from above.
- Go to your WordPress site's dashboard.
- Go to Plugins > Add New.
- Search for Code Snippets, then install and activate the plugin.
- Once installed and activated, go to Snippets in your dashboard menu.
- Click on Add New.
- Add a Title, which could be the title of this article.
- Paste the code you copied in step 1 to the Code section.
- Add a Description or Tags if you wish to do so. It is not required.
- Click on Save Changes and Activate to save the filter and activate it.
- Or click on Save Changes to save the filter and activate it later.
- Your action or filter is now stored and active on your site.