当帖子发布时,我已经在wordpress中编写了一个插件来执行操作 我正在使用 add_action('save_post','user_sf_project')操作。我可以从 wp_post 表中获取数据,但不能从 wp_postmeta 表。它显示为空。 需要帮助来获取 wp_postmeta
的值这是我的代码。
add_action('save_post','user_sf_project');
function user_sf_project($post_id){
$SOAP_CLIENT_BASEDIR = plugin_dir_path(__FILE__).'Force.com-Toolkit-for-PHP/soapclient/';
require_once ($SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once ($SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');
require_once ('Force.com-Toolkit-for-PHP/Samples/userAuth.php');
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection($SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
$mylogin = $mySforceConnection->login("username", "password");
$postdata = get_post($post_id);
$meta_values = get_post_meta( $post_id, 'salary', true );
$fields = array (
'Name' => $post_id,
'First_Name__c' => $postdata->post_title,
'Salary__c' => $meta_values,
);
$sObject = new SObject();
$sObject->fields = $fields;
$sObject->type = 'NewObject__c';
$createResponse = $mySforceConnection->create(array($sObject));
print_r($createResponse);
$ids = array();
foreach ($createResponse as $createResult) {
print_r($createResult);
array_push($ids, $createResult->id);
}
} catch (Exception $e) {
echo $mySforceConnection->getLastRequest();
echo $e->faultstring;
}
我无法使用meta_key从wp_postmeta获取meta_value。 请告诉我我在代码中犯了什么错误。