Link to home
Start Free TrialLog in
Avatar of andieje
andieje

asked on

Adding wordpress post to website remotely

Hi

I'm trying to insert a wordpress post into a remote database. I am doing this via curl i php

This is the data that is being sent as the arguments for the post. This is called args. Each element is url encoded

 
   ( [comment_status] => open [ping_status] => [post_author] => 2 [post_content] => %3Ch2%3EInstalling+the+T8+to+T5+converter%3C%2Fh2%3E%0D%0A%3Cimg+class%3D%22alignright+size-full+wp-image-389%22+alt%3D%22installation%22+src%3D%22http%3A%2F%2Fsaveiteasy.dev3.co.uk%2Fwp-content%2Fuploads%2Finstallation.jpg%22+width%3D%22300%22+height%3D%22400%22+%2F%3E%3Ca+title%3D%22Energys+Group%22+href%3D%22http%3A%2F%2Fwww.energysgroup.com%2F%22+target%3D%22_blank%22%3EEnergys+Group+%3C%2Fa%3Eis+able+to+a+deliver+a+UK-wide+turnkey+installation+of+low-carbon+retrofit+technologies+including+its+Save+It+Easy+-+T8+to+T5+device.%0D%0A%0D%0AThe+Energys+warrantied+turnkey+service+includes+supply+and+installation+of+the+low-carbon+T5+tube+and+equipment+as+a+single+package.%0D%0A%0D%0ADesigned+to+make+things+trouble-free+for+clients%2C+it+combines+our+unique+experience+of+retrofit+work+with+sensible+pricing%2C+scheduling+flexibility+and+rigorous+quality+control.%0D%0A%0D%0AEnergys+Group+provides%3A%0D%0A%3Cul%3E%0D%0A%09%3Cli%3EInstallation%2C+commissioning%2C+warranties+and+on-going+maintenance+programmes.%3C%2Fli%3E%0D%0A%09%3Cli%3ETurnkey+solutions%2C+which+reduce+time+and+effort+by+combining+product+supply%2C+installation+and+project+management+in+a+single+highly-competitive+package.%3C%2Fli%3E%0D%0A%09%3Cli%3EHands-on+training+and+commissioning%2C+which+is+available+to+customers+who+prefer+to+use+their+own+staff%2Fcontractors.+This+helps+to+ensure+the+installation+fully+conforms+to+standards.%3C%2Fli%3E%0D%0A%3C%2Ful%3E%0D%0A%3Ch3%3EMaintenance+and+support%3C%2Fh3%3E%0D%0AEnergys+Group+is+highly+experienced+in+the+installation+and+maintenance+of+its+range+of+low-carbon+T8+to+T5+retrofit+solutions.%0D%0A%0D%0AOur+dedicated+Customer+Services+Division+provides+warranty+support+and+can+also+perform+ongoing+maintenance+on+our+range+of+energy-efficient+lighting+converters.%0D%0A%0D%0AOur+commitment+to+customers+does+not+end+with+the+installation+of+Save+It+Easy.+We+offer+a+full+range+of+Service+Contracts%2C+which+are+designed+to+give+the+correct+level+of+maintenance+and+additional+peace+of+mind+to+prevent+or+cover+unexpected+failures.%0D%0A%0D%0AOperators+and+owners+of+large+sites+can+sign+up+to+an+individually-negotiated+agreement+which+will+take+care+of+all+the+costs+associated+with+lighting+on+site.%0D%0A%3Ch3%3EHealth+and+Safety%3C%2Fh3%3E%0D%0AEnergys+Group%E2%80%99s+highly+trained+Installation+Team+conforms+to+the+stringent+requirements+of+CHAS+%28Construction+Health+and+Safety+Scheme%29.%0D%0A%0D%0AAs+an+experienced+contractor%2C+we+have+operated+under+many+customers%E2%80%99+health+and+safety+policies+and+received+excellent+customer+references+as+a+result. [post_excerpt] => [post_name] => installation [post_parent] => 0 [post_password] => [post_status] => publish [post_title] => Installation [post_type] => page [to_ping] => No [menu_order] => 0 [guid] => http%3A%2F%2Fsaveiteasy.dev3.co.uk%2F%3Fpage_id%3D174 )

Open in new window


I am tryingto get the id of the page that was just created and nothing is coming back


$new_id = get_data('http://wxxxxxxx/insert_page.php',$args);

$new_id is nothing    It used to work fine when i was doing the curl as a get not a post
   
This is the get data function. There are no error messages
   
 
   
 
   function get_data($url, $data) {
       $fields = '';
       foreach($data as $key => $value) { 
          $fields .= $key . '=' . $value . '&'; 
       }
       rtrim($fields, '&');
        
       $post = curl_init();
    
       curl_setopt($post, CURLOPT_URL, $url);
       curl_setopt($post, CURLOPT_POST, count($data));
       curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
       curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
    
       $result = curl_exec($post);
    
       curl_close($post);
       
        echo "Curl : " . print_r(curl_getinfo($post)) . "<br/>";  // get error info
    	echo "cURL error number:" .curl_errno($post) . "<br/>"; // print error info
    	echo "\n\ncURL error:" . curl_error($post) . "<br/>"; 
    
    }

Open in new window


Is this anythig to do with the format of the array sent to the insert_post method. I didnt urlencode anything before.

Thanks in advance for any expertise you can share
ASKER CERTIFIED SOLUTION
Avatar of andieje
andieje

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial