WordPress.org

Forums

Having trouble in getting meta_value from wp_postmeta in plugin (1 post)

  1. maheshwarimani1991
    Member
    Posted 1 year ago #

    I have written a plugin in wordpress to action when a post gets posted i am using add_action('save_post','user_sf_project') action for doing so.I am able to get data from wp_post table but not from wp_postmeta table. It is showing empty for it. Need help for fetching values of wp_postmeta

    here is my code -

    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;
    }

    I am unable to get meta_value from wp_postmeta using meta_key. Please tell me what mistake i am doing in my code.
    The same also happened with wp_usermeta.

Topic Closed

This topic has been closed to new replies.

About this Topic