Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3609026
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:34:29+00:00 2026-05-18T21:34:29+00:00

I’m trying to post to WordPress using curl via PHP – I’m posting using

  • 0

I’m trying to post to WordPress using curl via PHP – I’m posting using the XMLRPC built into WordPress by default.

Posting is successful with the below code, but nothing is returned. I need to know some information about the post, such as it’s URL – I can do this if I have the ‘post ID’, which by looking at the xmlrpc.php file, it should return. Below is my code for posting:

    function post($username, $password, $title, $content, $url, $category=array(), $keywords='', $type='Wordpress')
{
    $encoding = 'UTF-8';

    $title = htmlentities($title,ENT_NOQUOTES,$encoding);
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);

    $reqparams = array(
        'title'=>$title,
        'description'=>$content,
        'mt_allow_comments'=>0,  // 1 to allow comments
        'mt_allow_pings'=>0,  // 1 to allow trackbacks
        'post_type'=>'post',
        'mt_keywords'=>$keywords,
        'categories'=>$category
    );
    $params = array(0,$username,$password,$reqparams,true);
    $request = xmlrpc_encode_request('metaWeblog.newPost',$params);
    $ch = curl_init();

    $fp = fopen('/home/*/public_html/file.txt', 'w+');

    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_STDERR, $fp);
    $results = curl_exec($ch);
    echo '<pre>'.print_r($results, true).'</pre>';
    curl_close($ch);
    return $results;

}

The echo '<pre>'.print_r($re... line just shows <pre></pre>. I have savd the verbose output of curl into a file, please find it below (I’ve starred out the URL):

* About to connect() to www.*******.com port 80 (#0)
*   Trying 87.106.55.179... * connected
* Connected to www.*******.com (87.*.*.179) port 80 (#0)
> POST /xmlrpc.php HTTP/1.1
Host: www.*******.com
Accept: */*
Content-Length: 1445
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

< HTTP/1.1 100 Continue
* Operation timed out after 1000 milliseconds with 0 bytes received
* Closing connection #0

As I said, the CODE DOES POST, BUT NOTHING IS RETURNED. Sorry to be blunt, but I know this will start off a torrent of pointless answers. So, should I be expecting a post ID to be returned, and if not, how can I easily get it returned?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:34:30+00:00Added an answer on May 18, 2026 at 9:34 pm

    Sod’s law. After posting I tried changing the max timeout time: curl_setopt($ch, CURLOPT_TIMEOUT, 1); to 10: curl_setopt($ch, CURLOPT_TIMEOUT, 10); and I get some nice XML returned with the post ID embedded.

    I haven’t deleted this post as I thought it might be useful for someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.