0

I am posting to wordpress in java using xmlrpc successfully using the following code

    // Hard-coded blog_ID
int blog_ID = 1;

// XML-RPC method
String xmlRpcMethod = "metaWeblog.newPost";

// Create our content struct
...

// You can specify whether or not you want the blog published
// immediately
boolean publish = true;

try {
    XmlRpcClient client = new XmlRpcClient(twtr2wp.xmlRpcUrl, false);

    Object token = client.invoke(xmlRpcMethod, new Object[] {
            new Integer(blog_ID), 
            twtr2wp.wpUsername, 
            twtr2wp.wpPassword,
            hmContent, 
            new Boolean(publish) });

    // The return is a String containing the postID
    System.out.println("Posted : " + token.toString());
} catch (Exception e) {
    e.printStackTrace();
}

Everything is working except for categories. I have seen that they need to be passed in an array but I have not been successful passing them like this:

hmContent.put("categories", "[Cat1,Cat2]");

Can anyone help me figure out why the categories are not showing up?

1 Answer 1

2

Just a guess in the dark here, have you tried to put String array instead of [Cat1, Cat2] into the hmContent ?

Something like this hmContent.put("categories", new String[]{"Cat1", "Cat2"});

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, not sure why that escaped me.

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.