F2P Filter: Modify the Meta Data of Imported Posts

The filter shown below allows you to modify the metadata of imported posts. This works very similarly to this filter.

NOTE: The plugin will prefix each meta key with “wprss_ftp_”. To avoid this, add an exclamation mark, “!”, at the beginning of the meta key. The plugin will automatically detect the exclamation mark, remove it, and skip adding the prefix.

NOTE: The post has already been inserted into the database at this stage.

add_filter( 'wprss_ftp_post_meta', 'my_custom_post_meta', 10, 4 );

 * Exposes the meta data of a post that results from import of a feed item. 
 * @param array $meta The original meta data array.
 * @param int $post_id The ID of the post, which is being processed.
 * @param int $feed_source The ID of the feed source post, which the current item is being imported by.
 * @param SimplePie_Item $feed_item The feed item, which is being imported.
 * @return array The new meta data array.
function my_custom_post_meta( $meta, $post_id, $feed_source, $feed_item ) {
    // Add meta data, with "wprss_ftp_" prefix
    $meta['my_meta'] = 'some value';

    // Add meta data, without the "wprss_ftp_" prefix. Uncomment the line below and comment out the line above to use this method.
    // $meta['!my_meta'] = 'some value';

    // Check feed source
    if ( $feed_source === 51 ) {
        // Remove meta added by the plugin (NOT RECOMMENDED)
        unset( $meta['import_date'] );
    // The feed object
    $feed = $feed_item->get_feed();
    /* @var $feed SimplePie */

    // Return the meta - IMPORTANT
    return $meta;

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