How to Set Up Feed to Post's Custom Field Mapping

The Feed to Post add-on's  Custom Field Mapping gives advanced users greater control over what data they can bring into their posts. It is most notably meant for users who import RSS data for use in custom post types, themes, or page builder plugins. 

NOTE: This feature requires the use of Custom Fields. Often, these are hidden in the Edit Post screen of your WordPress site.

If you are using the Gutenberg Editor, click on the three dots on the top right of your screen, then click Options and finally check the box for 'Custom Fields' under Advanced Panels.

If you are using the Classic Editor, open the Screen Options drawer from the top-right of the screen and tick the checkbox next to the label “Custom Fields”.

Setting up Custom Field Mapping

We'll explain how to set up custom field mapping with an example. Let's say you want to use this YouTube feed for the Best Hip Hop Releases in Australia and extract the data highlighted in the screenshot of the RSS feed below, which is the value of the <yt:channelId> tag, and the <link> tag's href attribute. The href attribute will be extracted for each imported feed item that is converted into a post.

The first step after setting up the feed source under RSS Aggregator > Feed Sources would be to scroll down to the Feed to Post - Custom Field Mapping section and click 'Detect namespaces in Feed Source':

The RSS feed in our example has the following namespaces:

  • Namespace yt  with URL:
  • Namespace media  with URL:

The Top Element of a Feed

The top element in a feed tells you what standard the source is using. <rss> is for RSS 2.0 and <feed> is for Atom. The YouTube feed in our example has <feed> as the top element, so it is using the Atom standard. A feed that uses <rss>  as the top element would be based on the RSS 2.0 standard.

This top element will have the feed's namespaces declared as attributes, and this YouTube feed has 3 namespaces. They are prefixed with xmlns ("xmlns" is short for XML NameSpace) and the name follows the: colon.

One is xmlns:yt , the second is xmlns:media and the last one has no name — it is just xmlns .

But notice that it still has a URL. Normally, RSS 2.0 feeds do not include the default namespace while Atom feeds include it anyway.

Therefore, this example feed needs to use the Atom namespace. 

Namespace URLs

The namespace URL like does not need to resolve into any particular page. This is why it will result in a 404 page when you open this in a browser window. This URL is just an identifier that is unique to the namespace.

Now that we are familiar with namespaces and have detected or identified which namespaces are used by the RSS feed, we can open another browser tab and navigate to RSS Aggregator > Settings > Feed to Post.

There, scroll down to the Custom Namespaces section and set it up like the screenshot below:

Click Save Settings at the bottom of this page.

Notice how we've copied over the names and URLs that we detected in the Feed to Post - Custom Field Mapping section earlier, plus we're adding details for the atom namespace:

  • Namespace yt  with URL:
  • Namespace media  with URL:
  • Namespace atom with URL:

The yt namespace is needed because we are looking for the data in the <yt:channelId> tag. The media namespace will be needed if you want to fetch data from a tag prefixed with media: like <media:title>. The atom namespace is needed because we are looking for the <link> tag's href attribute to show up in the custom meta for the post. Please note that a feed that contains <rss> as the top element will need to have 'No Namespace' selected in the Namespace dropdown.

Next, we'll need to refresh the Edit Feed Source page for this feed, and finalize the custom field mapping by setting up the values as in the screenshot below:

For the first entry, choose yt as the namespace, set channelId as the RSS tag, and set channel_id as the custom field placeholder. The custom field placeholder can be any text of your choice. It will be used as the name that identifies the custom field when it's mapped to the imported post.

Similarly, for the second entry, choose atom as the namespace, set link[href] as the RSS tag, and set youtube_url as the custom field placeholder. When you save link[href], you are sending an instruction to obtain the href attribute of the <link> RSS tag.

Click Update or Publish at the top right of the Edit Feed Source after setting this up.

Next, re-import your feed if you had already set it up earlier and add the custom field mapping later. This should be done by clicking Delete items and Fetch against the relevant feed source on the RSS Aggregator > Feed Sources page:

Finally, you should be able to see the custom fields mapped to each of your imported posts. Please refer to the note at the top of this article to know how to view the custom fields mapped to your posts.

Using Custom Fields Programmatically

The mapped custom field values will be available for you to access programmatically. You will need to use the get_post_meta in WordPress to access the value for the custom field you have mapped.

$meta_youtube_url = get_post_meta(get_the_ID(),'youtube_url',true);

echo $meta_youtube_url;

NOTE: This feature currently does not work with nested tags in the RSS feed. Only tags that are one level deep within the <item> or <entry> tags can be mapped to the imported posts. For example, if you have the following <item> tag in your feed, the content of <sr:image> can be mapped, but the content of <sr:barcode> cannot be mapped.

Still need help? Contact Us Contact Us