0

I am trying to connect to my wordpress installation in order to create posts of a specific kind. The code I am using for that is:

Include('../wp-includes/class-IXR.php');
$client = new IXR_Client('http://www.example.com/xmlrpc.php');


        $content = array(
            'title' => 'Test',
            'description' => 'content',
            'mt_allow_comments' => 0, // 1 to allow comments
            'mt_allow_pings' => 0, // 1 to allow trackbacks
            'post_type' => 'question',
            'mt_keywords' => 'test'
        );




if (!$client->query('metaWeblog.newPost','', 'admin','pass', $content, publish)) {
    die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
}
echo $client->getResponse();    //with Wordpress, will report the ID of the new post

When I try this code I get the following error:

An error occurred - 401:Invalid post type

I am positive question is a valid post type so I am not sure how to proceed from here.

Any help will be appreciated. Thanks

2
  • how is "question" registered? Commented Oct 19, 2015 at 3:18
  • Hi, thanks. I am not entirely sure because it is part of a theme I bought. What I see is the following URL when I click on the menu example.com/wp-admin/edit.php?post_type=question I am trying to find the piece of code where 'question' is registered, but it might take me a while. Thanks for your time, and if you have any clues I will appreciate it! Commented Oct 19, 2015 at 3:45

1 Answer 1

0

The wp.* methods that were added in WP 4.3 support custom post types. The old metaWeblog methods did not.

3
  • Thanks, I was looking at the same in the docs. I found some other answerds saying that it should work by setting 'post_type' to my type (other than post or page), but it looks it changed. Commented Oct 19, 2015 at 4:02
  • 1
    You're looking at the old metaWeblog methods, the new wp.* methods support custom post types. Commented Oct 19, 2015 at 4:35
  • I would like to post a side note: JSON API seems to be the future. Does new applications should be developed with it and old applications should move from XML-RPC to JSON API? In general, I think so. Commented Oct 19, 2015 at 8:05

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.