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 applies to the featured image (the one mapped via imageMark). For images inside the article content, see "Content images" below.
Content images
Purple Wires can import the images inside the article content into the WordPress media library, so that they can carry metadata such as a photo credit, just like the featured image. This is off by default: without it, only the featured image is downloaded and content images keep pointing to their original external URL.
To enable it, activate the source option Import content images into the media library. Each content image is then downloaded, attached to the imported article, and the image block points to the local media item instead of the external URL. If a download fails, the external image is kept. If Enable update detection is active for the source, the download is retried in the next three imports.
contentImageMark
Marks the element that holds the URL of each content image, e.g. the url attribute of each <media:content>.
contentImageMeta:fieldname[:format[:split]]
Uses the same syntax as featuredImageMeta (see "Featured image metadata" above), including the four reserved fieldname values caption, description, alt and title. The value is stored on the media item of the matching content image. The format i (image download) is not supported here; such values are skipped.
Each metadata value is paired with the image URL from the same element (e.g. the same <media:content>) and matched to the <img> in the article content by URL. The match ignores http/https and query strings. If an element repeats, e.g. one <media:credit> per role, the values are joined.
If no caption is mapped, the <figcaption> from the article content is used as the image caption.
Re-imports and updates reuse the article's existing media items, so no duplicates are created. A change in the image metadata alone, e.g. only the photo credit, is detected as an update. Each article keeps its own copy: two articles using the same image URL get one media item each, so neither overwrites the other's credit or caption.
With the option enabled, the featured image is also reused by its source URL instead of being downloaded again on every update. If it is the same image as a content image of the article, both share one media item and featuredImageMeta takes precedence.
Examples
<mediaContent::url>contentImageMark</mediaContent::url> marks the url attribute of each <media:content> element as a content image URL.
<mediaContent:mediaCredit>contentImageMeta:bild_autor</mediaContent:mediaCredit> stores the <media:credit> of the same <media:content> as the bild_autor meta field on the matching content image.
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