WordPress.org

Ready to get started?Download WordPress

Forums

wordpress XMLRC metaWebBlog custom field issue (1 post)

  1. bsikander
    Member
    Posted 1 year ago #

    Hello,
    I want to post articles to my blog from a C# desktop application. For this i am using XMLRC. The code without the custom fields is working fine.

    I will be thankful if you can help me solving the following: 1- Why the code that i wrote for custom fields in not working ? I want to set the All In One SEO pack plugin fields.

    2- How can i attach Featured Image ?

    Following is my code:

    public interface IgetCatList
    {
        [CookComputing.XmlRpc.XmlRpcMethod("metaWeblog.newPost")]
        string NewPage(int blogId, string strUserName, string strPassword, blogInfo content, int publish);
    
        [XmlRpcMethod("metaWeblog.newMediaObject", Description = "Add a media object to a post using the metaWeblog API. Returns media url as a string.")]
        MediaObjectUrl newMediaObject(int blogid,string username,string password,MediaObject mediaObject);
    }
    
    public struct customField
    {
        public string key;
        public string value;
    }
    
    public struct blogInfo
    {
        public string title;
        public string description;
        public string post_type;
        public string[] categories;
        public string mt_keywords;
        public string mt_excerpt;
        public customField[] custom_fields;
    }
    
    private void PostToBlogUsingXMLRC(string pTitle,string pPost)
        {
    
            blogInfo newBlogPost = default(blogInfo);
    
            newBlogPost.title = pTitle;
            newBlogPost.description = pPost;
            newBlogPost.categories = new string[] { "TechReviews" };
            newBlogPost.post_type = "post";
            newBlogPost.mt_excerpt = "this is excerpt";
            newBlogPost.mt_keywords = "keywrod";
            //aiosp
            //aioseop
            customField aioseoTitle = default(customField);
            aioseoTitle.key = "_aioseop_title";
            aioseoTitle.value = "This is SEO Title";
    
            customField aioseoDesc = default(customField);
            aioseoDesc.key = "_aioseop_description";
            aioseoDesc.value = "This is SEO description";
    
            customField aioseoKeyword = default(customField);
            aioseoKeyword.key = "_aioseop_keywords";
            aioseoKeyword.value = "This is SEO keywords";
    
            //customField thumbnailImage = default(customField);
            //thumbnailImage.key = "_thumbnail_id";
            //thumbnailImage.value= PostNewMediaObject();
    
            newBlogPost.custom_fields = new customField[] { aioseoTitle, aioseoDesc, aioseoKeyword };
    
            categories = (IgetCatList)XmlRpcProxyGen.Create(typeof(IgetCatList));
            clientProtocol = (XmlRpcClientProtocol)categories;
    
            clientProtocol.Url = "http://abc.com/xmlrpc.php";
    
            string result = null;
            result = "";
    
            try
            {
                result = categories.NewPage(1, "ID", "Pass", newBlogPost, 1);
    
                MessageBox.Show("Posted to Blog successfullly! Post ID : " + result);
                pTitle = "";
                pPost = "";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

Topic Closed

This topic has been closed to new replies.

About this Topic