Is there an XML Web Service that can get posts, categories and other data from the site?

I know that there is a JSON API Plugin and I think that is what I want with the major exception being that it only outputs JSON and there is no configuration that I can see for outputting XML. Is there an equivalent for an XML webservice or can I output it myself through some built-in WP functionality?

I'd like to output XML because I am looking to feed the data into a third party search engine tool that can integrate with XML web services.

Topic xml web-services Wordpress

Category Web


WordPress ships with an XML-RPC interface that's enabled by default. It gives you the ability to both retrieve and edit/create content on the site via XML.

There's quite a bit of detail about the API available on the Codex.


Updated

There aren't (to my knowledge) any existing systems in place that do XML over GET for WordPress. Webpages tend to be some form of (X)HTML already and, if following the XHTML spec closely, your theme alone might produce something parse-able.

However, that's not the only option in place.

If you take a look at some of the newer AMP work being done with WordPress, you'll see how developers are leveraging custom URL rewrite endpoints to serve different content for the same resource. For example:

You could use the same pattern to code an /xml rewrite endpoint that presents your post in whatever arbitrary markup as you need.

To get you started ...

Enable an endpoint

function xml_init() {
    add_rewrite_endpoint( 'xml', EP_PERMALINK );
}
add_action( 'init', 'xml_init' );

Intercept requests so you can prepare XML

function xml_maybe_change_markup() {
    if ( ! is_singular() || is_feed() ) return;

    // Only intercept the right requests
    if ( false === get_query_var( 'xml', false ) ) return;

    add_action( 'template_redirect', 'xml_render' );
}
add_action( 'wp', 'xml_maybe_change_markup' );

Actually render XML

function xml_render() {
    $post_id = get_queried_object_id();

    // Get the post, build your XML document, print it to the page

    exit;
}

As I don't know what exact output you need, I leave building the XML document as an exercise for you :-)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.