When I use XML-RPC to create a new post instead of wp_insert_post the post is created with wrong guid/URL. With XML-RPC the guid is created with ID not slug.
// Input data
$my_page = array();
$my_page["post_title"] = $alternatename_main;
$my_page["post_content"] = $postcontent;
$my_page["post_excerpt"] = $postexcerpt;
$my_page["post_status"] = "publish";
$my_page["post_date"] = date("Y-m-d H:i:s");
$my_page["post_author"] = 1;
$my_page['post_type'] = 'post';
$my_page["post_name"] = "test1234";
// Local insert
$my_page_id = wp_insert_post($my_page);
$wp_post_data = get_post($my_page_id);
$wp_guid = $wp_post_data->guid;
Result: $wp_guid = http://test/site/test1234/
// Insert XML-RPC
include_once( ABSPATH . WPINC . '/class-IXR.php' );
include_once( ABSPATH . WPINC . '/class-wp-http-ixr-client.php' );
$client = new WP_HTTP_IXR_Client('http://test/site/xmlrpc.php');
$client -> debug = true; //optional but useful
$username = "yyyyyy";
$password = "xxxxxx";
$params = array(0,$username,$password,$my_page);
$clientresult = $client->query('wp.newPost', $params);
$my_page_id = $client->getResponse();
$wp_guid = get_the_guid($my_page_id);
Result: $wp_guid = http://test/site/?p=12721
I have tested:
$wp_post_data = get_post($my_page_id);
$wp_slug = $wp_post_data->post_name;
$my_page_update = array();
$my_page_update["guid"] = "http://test/site/".$wp_slug."/";
$params = array(0,$username,$password,$my_page_id,$my_page_update);
$clientresult = $client->query('wp.editPost', $params);
But it doesn’t work.
The only solution I can find is to use raw sql:
UPDATE wp_posts SET guid='"http://test/site/".$wp_slug."/"' WHERE ID=".$my_page_id .";
I cant see any reason why the post is created with different guid, both post are created with the correct slug. A bug in wp.newPost? Does anyone have a answer? The test is done on the same wordpress installation.