当我使用XML-RPC而不是wp\\U insert\\U post创建新帖子时,该帖子是使用错误的guid/URL创建的。使用XML-RPC创建guid时,ID不是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
我测试过:
$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);
但它不起作用。
我能找到的唯一解决方案是使用原始sql:
UPDATE wp_posts SET guid=\'"http://test/site/".$wp_slug."/"\' WHERE ID=".$my_page_id .";
我看不出为什么这篇文章是用不同的guid创建的,这两篇文章都是用正确的slug创建的。wp中的错误。newPost?有人有答案吗?测试是在相同的wordpress安装上完成的。
SO网友:Torre
这是一个恼人的问题,但如果我这样做,有一种方法可以获得正确的链接:
$my_page_ask = array( \'link\', \'guid\' );
$params = array(0,$username,$password,$my_page_id, $my_page_ask);
$clientresult = $client->query(\'wp.getPost\', $params);
$post = $client->getResponse();
字符串链接包含正确的永久链接,如果:
$my_page["post_status"] = "publish";
它在草稿上不起作用,字符串guid仍然包含错误的值。