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:

$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

  • how is "question" registered? – Mark Kaplun Oct 19 '15 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! – JordanBel Oct 19 '15 at 3:45

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

  • 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. – JordanBel Oct 19 '15 at 4:02
  • 1
    You're looking at the old metaWeblog methods, the new wp.* methods support custom post types. – Milo Oct 19 '15 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. – cybmeta Oct 19 '15 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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