In short, I want to be able to modify the wp.getPost response to also return additional data, like the permalink. I thought it would be as easy as just calling the same function the xml-rpc code appears to call (wp_getPost):

add_filter( 'xmlrpc_methods', 'nc_xmlrpc_methods' );

function nc_xmlrpc_methods( $methods ) {
    $methods['wp.getPost'] = 'my_getPost';
    return $methods;

function nc_getPost( $args ) {
    global $wp_xmlrpc_server;
    $post_obj = $wp_xmlrpc_server->wp_getPost( $args );
    $post = $post_obj->to_array();

    $post['permalink'] = get_permalink( $post_obj->ID );

    return $post;

Regarding the permalink, I know getPost returns a link already, but it's not helpful for drafts because I need to know the future link, not the current path.

I saw this post and it suggests extending wp_xmlrpc_server. I'm entirely new to PHP so I'm not entirely sure why that's necessary unless I'm really building out an extension to the API. Am I missing something basic with my code?


1 Answer 1


Figured it out.

$post_obj['permalink'] = my_getDraftPermalink( $post_obj['post_id'] );

That's the correct syntax for getting the post_id. Then a custom function that gets the permalink the same way as the post dashboard UI is required. The dashboard uses get_sample_permalink and not get_permalink, which will return the draft path if the post isn't live.

function my_getDraftPermalink ( $post_id ) {
    require_once ABSPATH . '/wp-admin/includes/post.php';

    list( $permalink, $postname ) = get_sample_permalink( $post_id );

    return str_replace( '%postname%', $postname, $permalink );

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.