Taxonomies (Categories and Tags)

Feed to Post allows you to import RSS categories into any taxonomy that you want, for the Post Type in which you are importing.

We use the same terminology that WordPress uses.

Taxonomies, such as Categories or Tags, are in simple words grouping types. For instance,Categories is a Taxonomy that allows you to group Posts, which is a post type.

Terms are the groups themselves. For instance, if you have a Tag called “news”, then Tag is the taxonomy and “news” is a term.

The Taxonomy options can be found in the feed source Add New or Edit page, as well as the Feed to Post Settings page.

The options for both the feed and the settings page are merged when importing, so you can, for instance, set your tags in your settings page to use for all feed sources and then set the categories differently for each feed source.

The options are separated into sections. Each section is responsible for its own taxonomy.

Since each post type has its own taxonomies, changing the Post Type option will cause these options to change as well.

wpra-feed-to-post-taxonomies-new

Sections

The Add New button adds a new taxonomy section. For each section, you’ll first need to select a taxonomy from the dropdown on the left. The taxonomies shown in this dropdown depend on the selected Post Type for the feed or in the settings page.

The rest of the options are related to what you wish to add to the imported items. You can choose to add existing terms using the textbox-dropdown field, or tick the checkbox below it to auto create the terms from the feed source.

The buttons to the very right allow you to refresh the textbox-dropdown to get newly-added taxonomies or remove the section. The refresh button is particularly useful if you are adding or editing terms in another browser tab or window.

Your final options are to only apply the preceding terms if the title or content contain all or any of the keywords you can specify in the box below. All keywords/phrases must be separated by a comma as shown in the screenshot above. This is a way of filtering which imported items are assigned which taxonomies.

Ticking the auto create checkbox will import all the <category> tags in the RSS feed as terms into the selected taxonomy. If you’ve also chosen terms from the textbox-dropdown, they will also be added to the imported post.

NOTE: Since RSS feeds make no distinction between categories, tags or other taxonomies, ticking this check box will import all the <category> tags in the feed. For advanced handling of the auto created terms, see further below under the Modifying Auto Created Terms section.


The plugin allows you to modify the auto created terms, before they are processed and inserted into the database, giving you the ability to manipulate the categories found in the feed in any way you like. This done via the following filter:

The filter has 3 parameters:

  • An array of categories found (see structure below)
  • The taxonomy to which the categories belong
  • The ID of the feed source from which the post is being imported

The filter is expected to return an array of category arrays, similar to that passed as the first parameter.

Each category array must have a ‘name’ index. It can also optionally have an ‘args’ array index, which will be passed as the 3rd parameter to wp_insert_term. This can be useful to specify a category parent, or create the slug of the category manually. Refer to the documentation for wp_insert_term.

NOTE: The “parent” sub-argument is expected to be a category term slug, not an ID, even though wp_insert_term expects an ID. This is because the category terms will be inserted later during the post creation, and no IDs are available when the filter is run. Feed to Post will handle the conversion from slug to ID automatically when it is needed.

Examples:

  1. The example below will check if the post is being imported from the feed source with ID 3878, and will check if a “Plugin Reviews” category is found, and will change it into a “Plugins” category. All other categories are removed.
  2. The following example takes categories that are dash-separated pairs and splits them into two as child and parent categories:
  3. The example below allows you to map imported categories into your own. If the categories you specify do not exist, they will be created. The method below also works well with multiple feed source mappings: