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中的全部代码