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.

  1. Copy the code you need from above.
  2. Go to your WordPress site's dashboard.
  3. Go to Plugins > Add New.
  4. Search for Code Snippets, then install and activate the plugin.
  5. Once installed and activated, go to Snippets in your dashboard menu.
  6. Click on Add New.
  7. Add a Title, which could be the title of this article.
  8. Paste the code you copied in step 1 to the Code section.
  9. Add a Description or Tags if you wish to do so. It is not required.
  10. Click on Save Changes and Activate to save the filter and activate it.
    1. Or click on Save Changes to save the filter and activate it later.
  11. Your action or filter is now stored and active on your site.

Still need help? Contact Us Contact Us