自定义字段未显示在自定义 post 类型 post 中

Custom Fields not showing in custom post type post

我有一个名为 "Designer" 的自定义 post 类型,每个 post 将使用不同的唯一高级自定义字段,因为每个 post 都有唯一的 templates.With 下面的代码我可以在 Designer post 类型中为每个 post 提供规则并保存,但自定义字段不会显示在后端的 post 编辑页面上。 通常这段代码应该可以,但不知道代码发生了什么

请帮忙。

add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices )
{
    $choices['Custom Post types']['cpt_parent'] = 'Custom post type parent';

    return $choices;
}
add_filter('acf/location/rule_values/cpt_parent',    'acf_location_rules_values_cpt_parent');
function acf_location_rules_values_cpt_parent( $choices )
{
    $args = array(
        'hierarchical' => true,
        '_builtin' => false
    );
    $posttypes = get_post_types( $args );

    if( $posttypes )
    {
        foreach( $posttypes as $posttype ):

            if( $posttype != 'acf' ):
                $args = array(
                'post_type' => 'designer',
                'posts_per_page' => -1,
                'post_status' => 'publish'
                );
                $customposts = get_posts( $args );  
                if ( $customposts  ) {
                    foreach( $customposts as $custompost ){
                        $choices[ $custompost->ID] = $custompost->post_title;
                    }
                }
            endif;
        endforeach;
    }

    return $choices;
}

//MATCH THE RULE
add_filter('acf/location/rule_match/cpt_parent',              'acf_location_rules_match_cpt_parent', 10, 3);
function acf_location_rules_match_cpt_parent( $match, $rule, $options )
{
    global $post;
    $selected_post = (int) $rule['value'];

    // post parent
    $post_parent = $post->post_parent;
    if( $options['page_parent'] ) {

        $post_parent = $options['page_parent'];

    }

    if ($rule['operator'] == "=="){
        $match = ( $post_parent == $selected_post );
    }
    elseif ($rule['operator'] != "!="){
        $match = ( $post_parent != $selected_post );
    }

    return $match;
}

如果我对您的问题理解正确,请在 wp-admin post 编辑页面点击右上角的屏幕选项。在出现的菜单中,确保选择了自定义字段。这将使自定义字段出现以供编辑。

您的艺术家 Collection 字段组设置为仅出现在一个 post 上, post 设计师 Post 1 是设计师 Post类型。

我不明白所有代码的用途?只需为每个需要不同字段组和单独规则的 post 创建不同的字段组即可。

好的,抱歉,我现在明白了这个问题,我已经在我的本地安装中重现了这个问题。

在下面的代码行中,您正在查找 post_parent,但我认为您应该查找 ID。

我改变了这个:

$post_parent = $post->post_parent;

对此:

$post_parent = $post->ID;

它对我有用。