Custom XML Feeds for WordPress

Custom XML Feeds for WordPress

To create a custom XML feed go to WP All Export › New Export and select the post type that you want to export. Using WP All Export's custom XML syntax, customize your feed and generate your XML file.

Custom XML vs. Simple XML

With a Custom XML Feed export, you have complete and total control over the structure of the XML file. You literally write the XML feed by hand and can nest elements as deep as you want, add elements outside of the looping post element, create custom loops with PHP functions, and more.

The Simple XML Feed builder uses drag and drop to rearrange the XML elements. You can change the element names, but deep customization is not possible.

How to Build a Custom WordPress XML Feed

In the Export Type section, select Feed › Custom XML Feed:

Select Custom XML Feed

This will reveal the XML Editor, where you'll build your custom XML feed:

Custom XML Editor

To add export elements to the feed, you can drag-and-drop them from the Available Data section on the right side. If you want to add all of the elements from a certain sub-section under Available Data, simply drag the top element, like All Standard, into the XML Editor. After adding your elements, you can use the Preview button to see what your feed looks like with real data.

Everything between and will be repeated for each exported post, and there can only be one loop. You have complete control over the XML output and can manually edit any part of the XML feed in the editor.

Some characters in the data you're exporting might look like XML. CDATA tags are used to distinguish data that could be interpreted as XML markup, but should not be. By default, WP All Export will automatically add CDATA tags around any content that requires it. In the Advanced Options section you can choose to disable this functionality.

Repeating Fields and Arrays

Some fields, like images, have multiple values per post. WP All Export turns these fields into indexed arrays. Whenever WP All Export encounters an indexed array in an XML element it will repeat that element once for every value in the array.

For example, let's assume a post as two images attached to it: image1.jpg and image2.jpg. We want to have one XML element for every image URL. Here's what our XML template will look like:

     {Image URL}

And here's how our exported XML file will look:

     http://example.com/image1.jpg
     http://example.com/image2.jpg

WP All Export will do this with all indexed arrays that it comes across. So if you have a function that returns an indexed array, that XML element will be repeated for each value. Likewise, you can take a field like {Image URL} and turn it into a string, like this:

[implode("|",{Image Title})]

And you'll just get one XML element with all of the values, like this:

Image 1|Image 2

Using PHP Functions in a Custom XML Feed

Just like other export types, you can use custom or native PHP functions on export elements in a Custom XML Feed. The syntax is:

[function_name({Export Element})]

You can pass multiple export elements to your function if necessary.

This allows you to modify data on-the-fly, or output your own XML in the export feed. Just keep in mind that you must disable CDATA tags if you're outputting your own XML via PHP.

Related Docs

Simple XML

CSV & Excel

Standard Post Data

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注