Create a WordPress post with private custom fields (_customfieldname) not working

I am creating posts using WordPressSharp, but fail to set private custom field values that begin with an underscore upon creating the post.

I have read a ton of posts about modifying the file meta.php on the WordPress-site to alter register_meta and/or is_protected_meta, but have still not managed to get those custom fields to save the data I pass when creating the post.

Read More
using (var client = new WordPressClient(new WordPressSiteConfig
        {
            BaseUrl = "http://example.com",
            Username = "username",
            Password = "pass",
            BlogId = 1
        }))
        {
            Term t = new Term();
            t = client.GetTerm("category", 6);

            var terms = new List<Term>();
            terms.Add(t);

            var customFields = new[]
            {
                new CustomField
                {
                    Key = "_ct_text_5401d2f94abc9",
                    Value = "123"
                }
            };

            var post = new Post
            {
                PostType = "video", 
                Title = "title",
                Content = "description",
                PublishDateTime = DateTime.Now,
                Status = "draft", 
                CustomFields = customFields
            };

            var id = client.NewPost(post);
        }

The post is created successfully without issues, but why the private custom field is not getting the value set?

I have tried using both XMLRPC version 3 as well as 2.5, which is a common answer, but it does not apply to this particular issue.

Related posts

1 comment

  1. Actually finally found a solution to the issue. I have removed the protection of the custom fields through the addition of the below line to functions.php

    add_filter( 'is_protected_meta', '__return_false' ); 
    

    I do not know if this is the optimal solution security-wise, but it works.

Comments are closed.