2

I have succesfully create new post by using the api metaWeblog.newPost. I can see the new post created under the All Posts admin page. But the problem is it won't show on the homepage. Ii will only show after I go to the edit page of the new post and click Update. What could be causing the problem here?

The above scenario also happen even i use the wp_insert_post function. The new post is successfully created but won't show on homepage.

It will only show after i click the update button in the edit post page. (Nothing is really being updated the title, the content still the same. All i did was just click the update button).

This is the code i used:

    <?php

    $BLOGURL = "http://xxxx/wordpress";
    $USERNAME = "xxxx";
    $PASSWORD = "xxxx";

    function get_response($URL, $context) {
    if(!function_exists('curl_init')) {
    die ("Curl PHP package not installed\n");
    }

    /*Initializing CURL*/
    $curlHandle = curl_init();

    /*The URL to be downloaded is set*/
    curl_setopt($curlHandle, CURLOPT_URL, $URL);
    curl_setopt($curlHandle, CURLOPT_HEADER, false);
    curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
    curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $context);

    /*Now execute the CURL, download the URL specified*/
    $response = curl_exec($curlHandle);
    return $response;
    }

    /*Creating the metaWeblog.newPost request which takes on five parameters
    blogid,
    username,
    password*/

    /*The title of your post*/
    $title = "Sample Post Title";

    /*The contents of your post*/
    $description = "This is a sample post.";

    /*Forming the content of blog post*/
    $content['title'] = $title;
    $content['description'] = $description;
    $content['categories'] = array("mycategoryname");
    /*Whether the post has to be published*/
    $toPublish = true;
    $request = xmlrpc_encode_request("metaWeblog.newPost",
    array(1,$USERNAME, $PASSWORD, $content, $toPublish));

    /*Making the request to wordpress XMLRPC of your blog*/
    $xmlresponse = get_response($BLOGURL."/xmlrpc.php", $request);
    $response = xmlrpc_decode($xmlresponse);

   /*Printing the response on to the console*/
    print_r($response);
    echo "\n";
    ?>
2
  • I've found out that its caused by the plugin called qtranslate. After i deactivated it the new post will show on main page instantly but i needed this plugin. Anyone knows any workaround?
    – Joiwoo
    Oct 5, 2011 at 4:30
  • please ask a new question regarding the qtranslate plugin specifically. Also, please post an answer to this question explaining that the issue was caused by qtranslate and select that answer as "The" answer so that this question doesn't sit in the "unanswered questions" list.
    – EAMann
    Oct 27, 2011 at 16:04

1 Answer 1

3

Probably because your post is saved as draft. Try to set the post status to publish inside your $content array. E.g.

$content['post_status'] = 'publish';
1
  • Thanks for the response but that shouldn't be the case as i already include the code $toPublish = true; It actually showed as Published in the All Post section, it just won't show on the main page before i click update in the Edit Post section. But anyway I've gave your code a try but it didn't solve the problem. Thanks.
    – Joiwoo
    Oct 5, 2011 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.