Firstly, I know that XML-RPC is designed to send out the raw post data, but I need it to expand shortcodes out. I don't use it for posting so it won't be an issue there, but there are services that are grabbing posts from it and they're getting the shortcodes [] instead of the expanded shortcodes. I'd switch to RSS but I can't. I've expiremented but can't get do_shortcode to work in class-wp-xmlrpc-server.php Thanks.

  • Post your code, or answers are not possible.
    – fuxia
    Commented Jan 26, 2013 at 13:17

2 Answers 2


Explanation of the behavior

A shortcode is meant to be processed during runtime (when rendering & displaying a post on the public facing view). It is absolutely not meant to be a pre-processor during saving the post. The receiver simply doesn't have your parser (which is the function processing the shortcode) and therefore will get the raw result.

How to "fix" it

Just a note upfront: When you're doing this, it won't be reversible. The shortcode will get transformed to whatever it is replaced with and the result will then be saved as post content.

You will want to use the

to pre-process the post and replace the shortcode tag with it's actual content. Another option you might want to consider is the


To grab the shortcode you'll want to use get_shortcode_regex().

Hooks and XML RPC?

I'm not sure if the following works. It is well known that one can extend the XML RPC interface, but it seems that there're options/hooks to alter the returned values (at least it also does query for posts).

AS Matthew Murow explains, you could check (in a plugin) if you have an XML RPC request and then intercept during the hook:

if ( 
    defined ( 'XMLRPC_REQUEST' )
    add_action( 'xmlrpc_call', 'example_xmlrpc_posts_callback' );

Inside your callback, hook into the pre_get_posts (...) filter

This would look similar to this:

function example_xmlrpc_posts_callback( $task )
    if ( 'wp.getPosts' !== $task )

    add_filter( 'pre_get_posts', 'xmlrpc_pre_get_posts' );
function xmlrpc_pre_get_posts( $data )
    // Only run once - do not intercept later queries
    remove_filter( current_filter(), __FUNCTION__, 10 );

    // Alter output:
    // pre-process shortcodes

    return $data;
  • Thanks, this is a very clever solution, but it's not feasible for me as the shortcodes change output based on certain circumstances so baking them into the post would cause other issues. Is there really no way to process shortcodes before sending out the post through xml-rpc? Commented Jan 26, 2013 at 12:30
  • @TrevorAnderson Found a filter that may help you. See example.
    – kaiser
    Commented Jan 26, 2013 at 12:43

This is not the way the editing methods of XML-RPC implement by WordPress meant to be used. XML-RPC is a publishing protocol and you basically want to break the most basic rule of editing that fetching a file and saving it without modifications will result in exactly the same file.

On practical level, you will need to differentiate between users to those that get the "raw" data and those that get the processed one. Once you have done it you can hook on the xmlrpc_prepare_post filter


function wpse_83217_xml_post($_post, $post, $fields) {
  if (user gets processed post) {
    $_post['post_content'] = do_shortcodes($post['post_content']);
  return $_post;

untetsed, and have no idea if you have to run anything else before calling do_shortcodes for it to work (maybe set the global $post var, maybe need to use any of the other filters of the_content filter).

But what you really should do is declare a new XML-RPC method with the xmlrpc_methods filter and handle it anyway you want. This will require the clients to be adjusted as well, but it is the cleaner way to achieve what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.