0

Im trying to to write a program in C# and I'm stuck. The program suppose to create a post on wordpress via xmlrpc. I can create the post successfully but I have problems creating custom fields for the post. So when I open created post, custom fields are never there. I hope some of you gurus can help me as I am stuck for 3 days now and cant figure out what to do, feel absolutely helpless:(

Heres some code:

public struct customField
        {
            public string key;
            public string value; 
        }
        public struct newPost
        {
            public string[] categories;
            public string title;
            public string description;
            public string mt_excerpt;
            public customField[] cf;
        }
public interface IcreatePost
       {
           [CookComputing.XmlRpc.XmlRpcMethod("metaWeblog.newPost")]
           string NewPost(int blogId, string strUserName,
               string strPassword, newPost content, int publish);
       }

Heres how I set values for the object

    customField newCustomField2 = default(customField);

    newCustomField2.key = "some data";

    newCustomField2.value = "some data";


    newPost newBlogPost = default(newPost);
    newBlogPost.title = "Some Title";
    newBlogPost.description = "Some Content";
    newBlogPost.cf = new customField[] { newCustomField2 };
createPost(newBlogPost);

Function called:

public void createPost(newPost np)
        {

            string postid;
            icp = (IcreatePost)XmlRpcProxyGen.Create(typeof(IcreatePost));
            clientProtocol = (XmlRpcClientProtocol)icp;
            clientProtocol.Url = "http://127.0.0.1/xmlrpc.php";
            try
            {
                postid = icp.NewPost(1, "admin", "1234", np, 1); 

            }
            catch (Exception ex)
            {
                MessageBox.Show("createPost ERROR ->"+ ex.Message);
            }
        }

1 Answer 1

2

My only guess here would be that there is a naming mismatch in your parameters. The documentation that I've seen says that the field inside the newPost struct should be custom_fields rather than cf:

public struct newPost
{
    public string[] categories;
    public string title;
    public string description;
    public string mt_excerpt;
    public customField[] custom_fields;
}
0

Your Answer

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

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