Purple Wires: Conditional imports
Purple Hub
Summary
Purple Wires allows conditional imports, learn how to import data based on conditions with this article. From taxonomy import and conversion to fetching generic meta data, learn how to define allocations and conditions for meta fields.
Preconditions
- Have an Admin role in Purple Hub for being able to configure Purple Wires. Find here an Purple Hub: Overview of roles & rights
Description
Import based on conditions
If not using the 'Mapping configurator' you can define your own configuration by the following rules.
Taxonomy import
Taxonomy split up
taxonomyItem:convert[:split] where taxonomy can be 'category', 'tag' or any qualified own taxonomy slug.
Split Example
categoryItem:convert:/ on fetched data "germany/news/economy" will return the three categories 'germany', 'news' and 'economy'.
mytaxItem:convert on fetched data "germany news economy" will return the three elements 'germany', 'news' and 'economy' for own taxonomy 'My Tax' (with the slug 'mytax')
Taxonomy conversion
taxonomyItem:match:allocation:condition where taxonomy can be 'category', 'tag' or any qualified own taxonomy slug.
Argument match defines that the allocation string will be set by defined condition rule. This will happen after an optional conversion (as described before)
Example
categoryItem:match:germany:deutschland on fetched data "germany" will return the category 'deutschland'.
categoryItem:convert:/ and categoryItem:match:germany:deutschland on fetched data "germany/news/economy" will result in return of the three categories 'deutschland', 'news' and 'economy'
Value Mapping
By using the !! operator it is possible to create a value mapping to configure which value should be imported as which term. Example:
<importValues>categoryItem:match::!!Example=Example 123|Example2=Example 2 123</importValues>In this example, the values of the tag "importValues" are imported to the taxonomy "category". When the imported value is "Example", it is imported as the term "Example 123", and in the same way "Example2" is imported as "Example 2 123".
All other values are imported with as they are.
Fallback
It is possible to define a fallback value that gets applied when no matching element can be found. Instead, the fallback then gets set. This fallback can be configured via the mapping configuration UI or by setting it in the schema using the syntax |fallback=><fallback-value>. Example:
Meta import
Generic meta fetching
metaItem:fieldname[:format[:split]]
- Argument fieldname is the name of the meta-field
- Argument format (optional) can be r (repeater)
- If 'repeater' is choosen as format, the first param needs to be defined in ACF fieldname syntax, e.g. repeater%item, where first value (repeater) describes the repeaters name and second value (item) describes the repeaters subfield. The third parameter split will be the char to split up the given string. If param is empty, data will be split by blank spaces.
ACF Image Import
<mediaContent::url>metaItem:<acf-slug>:i</mediaContent::url>
It is possible to map images to ACFs of type image. Above is an example of how this works. The import recognizes the image by the argument :i
Featured image metadata
featuredImageMeta:fieldname[:format[:split]]
Uses the same syntax as metaItem (see "Generic meta fetching" above), but the value is stored on the downloaded featured image attachment instead of the article itself. Use this for fields that describe the image rather than the article, e.g. a photo credit or image description.
Four fieldname values are reserved for WordPress' own image fields. They are written to the media item itself instead of a custom field, and Purple publishes them as the image's properties:
- caption – the media caption
- description – the media description
- alt – the alternative text
- title – the media title
Examples
<imageCaption>featuredImageMeta:caption</imageCaption> sets the WordPress media caption of the article's featured image, which is published as the image's caption property.
<imageCredit>featuredImageMeta:bild_autor</imageCredit> stores the fetched value as the bild_autor meta field on the article's featured image attachment, not on the article post.
This only applies to the featured image (the one mapped via imageMark); in-content images are not downloaded into the media library and can't carry this kind of metadata.
Allocations & conditions
metaItem:fieldname:allocation
Within meta-storage you can define allocations where allocation will be set, if XML element value is not empty. Reserved single chars are 's', 'a' and 't'.
metaItem:fieldname:allocation:==string
If the XML element value is equal to string, the allocation will be done.
metaItem:fieldname:allocation:!=string
If the XML element value isn't equal to string, the allocation will be done.
metaItem:fieldname:allocation:%=string
If the XML element value contains string, the allocation will be done.
metaItem:fieldname:allocation:%!string
If the XML element value doesn't contain string, the allocation will be done.
'Equality Conditions' are case-sensitive, 'containing conditions' are not case-sensitive