Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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
Php 使用筛选器修改已注册的自定义帖子类型的参数_Php_Arrays_Wordpress_Arguments_Custom Post Type - Fatal编程技术网

Php 使用筛选器修改已注册的自定义帖子类型的参数

Php 使用筛选器修改已注册的自定义帖子类型的参数,php,arrays,wordpress,arguments,custom-post-type,Php,Arrays,Wordpress,Arguments,Custom Post Type,我正在尝试将第三方插件已注册的自定义帖子类型的show\u in\u rest参数从false设置为true。感谢插件作者提供了一个参数过滤器并提供了一个示例(参见下面的第一个代码块)知道如何将上述参数设置为true吗? 这是CPT寄存器功能 public function register_client() { $labels = apply_filters( 'business_manager_client_labels', array( 'name'

我正在尝试将第三方插件已注册的自定义帖子类型的
show\u in\u rest
参数从
false
设置为
true
。感谢插件作者提供了一个参数过滤器并提供了一个示例(参见下面的第一个代码块)知道如何将上述参数设置为true吗?

这是CPT寄存器功能

    public function register_client() {

    $labels = apply_filters( 'business_manager_client_labels', array(
        'name'                  => _x( '%2$s', 'post type general name', 'business-manager' ),
        'singular_name'         => _x( '%1$s', 'post type singular name', 'business-manager' ),
        'add_new'               => __( 'New %1s', 'business-manager' ),
        'add_new_item'          => __( 'Add New %1$s', 'business-manager' ),
        'edit_item'             => __( 'Edit %1$s', 'business-manager' ),
        'new_item'              => __( 'New %1$s', 'business-manager' ),
        'all_items'             => __( '%2$s', 'business-manager' ),
        'view_item'             => __( 'View %1$s', 'business-manager' ),
        'search_items'          => __( 'Search %2$s', 'business-manager' ),
        'not_found'             => __( 'No %2$s found', 'business-manager' ),
        'not_found_in_trash'    => __( 'No %2$s found in Trash', 'business-manager' ),
        'parent_item_colon'     => '',
        'menu_name'             => _x( '%2$s', 'admin menu', 'business-manager' ),
        'filter_items_list'     => __( 'Filter %2$s list', 'business-manager' ),
        'items_list_navigation' => __( '%2$s list navigation', 'business-manager' ),
        'items_list'            => __( '%2$s list', 'business-manager' ),
    ) );

    foreach ( $labels as $key => $value ) {
        $labels[ $key ] = sprintf( $value, business_manager_label_client_single(), business_manager_label_client_plural() );
    }

    $args = array(
        'labels'                => $labels,
        'public'                => false,
        'show_in_rest'          => false,
        'exclude_from_search'   => true,
        'publicly_queryable'    => false,
        'show_ui'               => true,
        'show_in_menu'          => false, // we are using custom add_submenu_page
        'query_var'             => true,
        'capability_type'       => 'post',
        'map_meta_cap'          => true,
        'has_archive'           => false,
        'hierarchical'          => false,
        'supports'              => array( 'title' ),
    );

    register_post_type( 'bm-client', apply_filters( 'business_manager_client_post_type_args', $args ) );

}
这是提供的示例

add_filter( 'business_manager_employee_post_type_args', 'example_function_for_employee_post_type', 10, 1 );

function example_function_for_employee_post_type( $args ) {
    print( $args ); //print the return value
    return $args;
}

请尝试下面的代码。您可以访问“$args”参数中的“show_in_rest”键,并通过true更新该值

add_filter( 'business_manager_employee_post_type_args', 'example_function_for_employee_post_type', 10, 1 );
function example_function_for_employee_post_type( $args ) {
    $args['show_in_rest'] = true;
    return $args;
}

Thx-如何一次修改多个参数?您可以将此“$args['show_in_rest']=true;”复制到同一行,并将新键添加到$args并将值设置为该行。