Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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";
    ?>
share|improve this question
    
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 '11 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 '11 at 16:04

1 Answer 1

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';
share|improve this answer
    
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 '11 at 4:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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