我用高级自定义字段创建了一些自定义字段,并将它们设置为显示在名为X的自定义帖子类型中(帖子类型等于X)。
但我只需要将它们显示在这个自定义帖子类型的特定页面上,而不是所有页面上。
我该怎么做?
我用高级自定义字段创建了一些自定义字段,并将它们设置为显示在名为X的自定义帖子类型中(帖子类型等于X)。
但我只需要将它们显示在这个自定义帖子类型的特定页面上,而不是所有页面上。
我该怎么做?
您不能通过ACF设置页执行此操作吗?您可以选择Post并将其设置为与标题相等。
Edit
更新图像以进行澄清Edit 2
事实证明,在显示标题下拉列表时,ACF不会查询自定义类型。要包含所有帖子类型,请在/core/admin/meta\\u box\\u位置。php,更改<div rel="post">
<?php
$choices = array();
foreach(get_posts(array(\'numberposts\'=>\'-1\')) as $v)
{
$choices[$v->ID] = $v->post_title;
}
$this->create_field(array(
\'type\' => \'select\',
\'name\' => \'location[rules][\'.$k.\'][value]\',
\'value\' => $rule[\'value\'],
\'choices\' => $choices,
));
?>
</div>
至<div rel="post">
<?php
$choices = array();
foreach(get_posts(array(\'numberposts\'=>\'-1\', \'post_type\'=>\'any\')) as $v)
{
$choices[$v->ID] = $v->post_title;
}
$this->create_field(array(
\'type\' => \'select\',
\'name\' => \'location[rules][\'.$k.\'][value]\',
\'value\' => $rule[\'value\'],
\'choices\' => $choices,
));
?>
</div>
如果您指的是删除您在帖子中通过PHP添加的某些字段。php或post new。php,当post类型满足特定条件时,可以使用acf\\u remove\\u local\\u field($key)函数-请参阅https://www.advancedcustomfields.com/resources/register-fields-via-php/
我遵循以下思路:
<?php
// Add Local Field Groups and Local Fields
add_action(\'init\', array($this, \'function_to_add_fields_to_all_post_types\'), 999);
// Notice how the priority is higher on this set of add_action functions so it runs after the initial setup of the fields
// Remove Fields From Edit Post Screen
if ( $pagenow == \'post.php\' && get_post_type($_GET[\'post\']) != \'cpt\' ) {
add_action(\'init\', array($this, \'remove_fields_from_cpt\'), 9999);
}
// Remove Fields From New Post Screen
if ( $pagenow == \'post-new.php\' ) {
if(!isset($_GET[\'post_type\']) || $_GET[\'post_type\'] != \'cpt\'){
add_action(\'init\', array($this, \'remove_fields_from_cpt\'), 9999);
}
}
function function_to_add_fields_to_all_post_types(){
// Add Local Fields using acf_add_local_field_group() or acf_add_local_field()
}
function remove_fields_from_cpt(){
// Note: The \'key\' for your field is not the same as it\'s \'name\'
acf_remove_local_field( \'key\');
}
我发现,仅在特定的管理屏幕上添加特定的字段就破坏了一些Ajax查找功能,因此添加到全部,然后从特定的管理屏幕中删除。也许有一种更有效的方法可以做到这一点,但这对我来说很有效。
以下是一种更有效的方法:
这将检查编辑和添加屏幕,并使用“acf\\u remove\\u local\\u field($key)”功能按键删除所选字段。
add_action(\'init\', \'remove_fields_from_cpt\', 9999);
function remove_fields_from_cpt(){
global $pagenow;
// Remove ACF fields from add/edit post
if ( in_array( $pagenow, array( \'post.php\', \'post-new.php\' ), true )
&& isset($_GET[\'post\']) || isset($_GET[\'post_type\'])
&& in_array(\'YOUR_POST_TYPE\', array(get_post_type( $_GET[\'post\']),
get_post_type( $_GET[\'post_type\']) )) ) {
$key = \'FIELD_KEY\';
acf_remove_local_field($key);
}
}
我用高级自定义字段创建了一些自定义字段,并将它们设置为显示在名为X的自定义帖子类型中(帖子类型等于X)。
但我只需要将它们显示在这个自定义帖子类型的特定页面上,而不是所有页面上。
我该怎么做?
您不能通过ACF设置页执行此操作吗?您可以选择Post并将其设置为与标题相等。
Edit
更新图像以进行澄清Edit 2
事实证明,在显示标题下拉列表时,ACF不会查询自定义类型。要包含所有帖子类型,请在/core/admin/meta\\u box\\u位置。php,更改<div rel="post">
<?php
$choices = array();
foreach(get_posts(array(\'numberposts\'=>\'-1\')) as $v)
{
$choices[$v->ID] = $v->post_title;
}
$this->create_field(array(
\'type\' => \'select\',
\'name\' => \'location[rules][\'.$k.\'][value]\',
\'value\' => $rule[\'value\'],
\'choices\' => $choices,
));
?>
</div>
至<div rel="post">
<?php
$choices = array();
foreach(get_posts(array(\'numberposts\'=>\'-1\', \'post_type\'=>\'any\')) as $v)
{
$choices[$v->ID] = $v->post_title;
}
$this->create_field(array(
\'type\' => \'select\',
\'name\' => \'location[rules][\'.$k.\'][value]\',
\'value\' => $rule[\'value\'],
\'choices\' => $choices,
));
?>
</div>
如果您指的是删除您在帖子中通过PHP添加的某些字段。php或post new。php,当post类型满足特定条件时,可以使用acf\\u remove\\u local\\u field($key)函数-请参阅https://www.advancedcustomfields.com/resources/register-fields-via-php/
我遵循以下思路:
<?php
// Add Local Field Groups and Local Fields
add_action(\'init\', array($this, \'function_to_add_fields_to_all_post_types\'), 999);
// Notice how the priority is higher on this set of add_action functions so it runs after the initial setup of the fields
// Remove Fields From Edit Post Screen
if ( $pagenow == \'post.php\' && get_post_type($_GET[\'post\']) != \'cpt\' ) {
add_action(\'init\', array($this, \'remove_fields_from_cpt\'), 9999);
}
// Remove Fields From New Post Screen
if ( $pagenow == \'post-new.php\' ) {
if(!isset($_GET[\'post_type\']) || $_GET[\'post_type\'] != \'cpt\'){
add_action(\'init\', array($this, \'remove_fields_from_cpt\'), 9999);
}
}
function function_to_add_fields_to_all_post_types(){
// Add Local Fields using acf_add_local_field_group() or acf_add_local_field()
}
function remove_fields_from_cpt(){
// Note: The \'key\' for your field is not the same as it\'s \'name\'
acf_remove_local_field( \'key\');
}
我发现,仅在特定的管理屏幕上添加特定的字段就破坏了一些Ajax查找功能,因此添加到全部,然后从特定的管理屏幕中删除。也许有一种更有效的方法可以做到这一点,但这对我来说很有效。
以下是一种更有效的方法:
这将检查编辑和添加屏幕,并使用“acf\\u remove\\u local\\u field($key)”功能按键删除所选字段。
add_action(\'init\', \'remove_fields_from_cpt\', 9999);
function remove_fields_from_cpt(){
global $pagenow;
// Remove ACF fields from add/edit post
if ( in_array( $pagenow, array( \'post.php\', \'post-new.php\' ), true )
&& isset($_GET[\'post\']) || isset($_GET[\'post_type\'])
&& in_array(\'YOUR_POST_TYPE\', array(get_post_type( $_GET[\'post\']),
get_post_type( $_GET[\'post_type\']) )) ) {
$key = \'FIELD_KEY\';
acf_remove_local_field($key);
}
}
一切都好吗<我需要wp-list-table 也要显示custom-fields 在每个custom-post 我有,但我不知道如何做到这一点,在这幅图中,它显示了带有字段的表格:Title, Author and Publication Date: 我想要的是能够选择custom-fields 将出现,例如以下示例Title, Carta, Naipe, Author, and Date of Publication: