Feed to Post Filter: Only Import Content from Specific Authors

It is possible to restrict the importing of posts depending on their author when using Feed to Post.

This is done by hooking into  wprss_insert_post_item_conditionals and checking the author for the feed item.

The below code demonstrates this by restricting importing to items that have the author  “Jean Galea”.

add_filter( 'wprss_insert_post_item_conditionals', 'author_conditional', 10 , 3 );

function author_conditional( $item, $source, $permalink ) {
    $wanted_author = "Jean Galea";
    // Get the author, and proceed only if the author is present
    if ( $author = $item->get_author() ) {
        $name = trim( $author->get_name() );
        // If no author, don't import. Return NULL
        if ( $name === NULL || !is_string( $name ) || $name === '' ) {
            return NULL;
        // Check if author is the author we want
        if ( strcasecmp( $name, $wanted_author ) === 0 ) {
            return $item;
        } else return NULL;
    // If no author specified, do not import. Return NULL
    return NULL;

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