Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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 WordPress:get\u post\u type\u object()为CPT返回NULL_Php_Wordpress_Custom Post Type - Fatal编程技术网

Php WordPress:get\u post\u type\u object()为CPT返回NULL

Php WordPress:get\u post\u type\u object()为CPT返回NULL,php,wordpress,custom-post-type,Php,Wordpress,Custom Post Type,函数get\u post\u type\u object()为我的CPT返回NULL。对于默认的帖子类型,将返回信息 以下是我的一个CPTs配置: function cptui_register_my_cpts_discurso() { /** * Post Type: Discursos. */ $labels = array( "name" => __( "Discursos", "foo" ), "singula

函数
get\u post\u type\u object()
为我的CPT返回NULL。对于默认的帖子类型,将返回信息

以下是我的一个CPTs配置:

function cptui_register_my_cpts_discurso() {

    /**
     * Post Type: Discursos.
     */

    $labels = array(
        "name" => __( "Discursos", "foo" ),
        "singular_name" => __( "Discurso", "foo" ),
    );

    $args = array(
        "label" => __( "Discursos", "foo" ),
        "labels" => $labels,
        "description" => "",
        "public" => true,
        "publicly_queryable" => true,
        "show_ui" => true,
        "show_in_rest" => true,
        "rest_base" => "",
        "has_archive" => true,
        "show_in_menu" => true,
        "exclude_from_search" => false,
        "capability_type" => "post",
        "map_meta_cap" => true,
        "hierarchical" => false,
        "rewrite" => array( "slug" => "discurso", "with_front" => true ),
        "query_var" => true,
        "menu_icon" => "dashicons-format-chat",
        "supports" => array( "title", "editor", "revisions", "author" ),
    );

    register_post_type( "discurso", $args );
}

add_action( 'init', 'cptui_register_my_cpts_discurso' );
获取post类型对象

$obj = get_post_type_object( 'discurso' );

尝试在动作中使用它,它可能是
init
wp
,如下所示

function cptui_register_my_cpts_discurso(){
    ....
    ....
    register_post_type( "discurso", $args );

    // Get your object
    $obj = get_post_type_object( 'discurso' );
}
add_action( 'init', 'cptui_register_my_cpts_discurso' );
或者尝试
wp
操作

function just_another_function(){

    // Get your object
    $obj = get_post_type_object( 'discurso' );
}
add_action( 'wp', 'just_another_function' );

希望这有帮助。

在我的functions.php文件中,
$obj=get\u post\u type\u对象('discurso')的代码在哪里除非你发布代码,否则没有人能帮你you@Dipak这是myfunctions.php中的全部代码