Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 创建一个WordPress帖子,其中私有自定义字段(_customfieldname)不起作用_C#_Wordpress_Wordpresssharp - Fatal编程技术网

C# 创建一个WordPress帖子,其中私有自定义字段(_customfieldname)不起作用

C# 创建一个WordPress帖子,其中私有自定义字段(_customfieldname)不起作用,c#,wordpress,wordpresssharp,C#,Wordpress,Wordpresssharp,我正在使用WordPressSharp创建帖子,但在创建帖子时无法设置以下划线开头的私有自定义字段值 我读过很多关于修改WordPress站点上的文件meta.php以改变register\u meta和/或受保护\u meta,但仍然没有设法让这些自定义字段保存我在创建帖子时传递的数据 using (var client = new WordPressClient(new WordPressSiteConfig { BaseUrl = "http://e

我正在使用WordPressSharp创建帖子,但在创建帖子时无法设置以下划线开头的私有自定义字段值

我读过很多关于修改WordPress站点上的文件
meta.php
以改变
register\u meta
和/或
受保护\u meta
,但仍然没有设法让这些自定义字段保存我在创建帖子时传递的数据

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);
        }
使用(var-client=new-WordPressClient(new-WordPressSiteConfig
{
BaseUrl=”http://example.com",
Username=“Username”,
Password=“pass”,
BlogId=1
}))
{
术语t=新术语();
t=client.GetTerm(“category”,6);
var terms=新列表();
条款。添加(t);
var customFields=new[]
{
新CustomField
{
Key=“\u ct\u text\u 5401d2f94abc9”,
Value=“123”
}
};
var post=新职位
{
PostType=“视频”,
Title=“Title”,
Content=“description”,
PublishDateTime=日期时间。现在,
Status=“draft”,
CustomFields=CustomFields
};
var id=client.NewPost(post);
}
帖子成功创建,没有问题,但是为什么私有自定义字段没有获得值集


我尝试使用XMLRPC版本3和2.5,这是一个常见的答案,但它不适用于这个特定问题。

实际上最终找到了解决问题的方法。通过在functions.php中添加以下行,我删除了对自定义字段的保护

add_filter( 'is_protected_meta', '__return_false' ); 
我不知道这是否是安全方面的最佳解决方案,但它是有效的