我想为WordPress创建类似[流派]的短代码。
add_action( \'init\', \'cptui_register_my_cpts_movie\' );
function cptui_register_my_cpts_movie() {
$labels = array(
"name" => __( \'MOVIE\', \'\' ),
"singular_name" => __( \'Movie\', \'\' ),
"menu_name" => __( \'MOVIES LIBRARY\', \'\' ),
"all_items" => __( \'All Movies\', \'\' ),
"add_new" => __( \'Add New Movie\', \'\' ),
"add_new_item" => __( \'Add New Movie\', \'\' ),
"edit" => __( \'Edit\', \'\' ),
"edit_item" => __( \'Edit Movie\', \'\' ),
"new_item" => __( \'New Movie\', \'\' ),
"view" => __( \'View\', \'\' ),
"view_item" => __( \'View Movie\', \'\' ),
"search_items" => __( \'Search Movie\', \'\' ),
"not_found" => __( \'No Movies found\', \'\' ),
"not_found_in_trash" => __( \'No Movies found in Trash\', \'\' ),
"parent_item_colon" => __( \'Parent Movie\', \'\' ),
);
$args = array(
"label" => __( \'MOVIE\', \'\' ),
"labels" => $labels,
"description" => "All Publish Tools for Movies",
"public" => true,
"publicly_queryable" => false,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => false,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "movie", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "editor", "comments", "revisions", "thumbnail" ),
"taxonomies" => array( "genre", "year", "quality", "country", "awards", "type", "stars", "subtitle" ),
);
register_post_type( "movie", $args );
// End of cptui_register_my_cpts_movie()
}
我想在短代码中显示“流派”
function shortcode_for_genre() {
ob_start();
the_terms( $post->ID, array( \'taxonomy\' => \'genre\',), \'\', \', \', \' \' );
return ob_get_clean();
}
add_shortcode (\'genre\', \'shortcode_for_genre\');
我尝试过上述代码和其他一些代码,但没有一个有效。这个短代码显示了帖子的类型。喜欢戏剧,动作。等