0

我正在使用新的自定义帖子类型为 wordpress 网站开发一个插件。但是,当我使用 wordpress 的内置函数来获取帖子类型名称 (get_post_type()) 时,它会返回“post”而不是“destinations”。有人可以帮我吗?

这里是注册帖子类型的代码:

// Register Custom Post Type
function paradises_destinations_install() 
{

    $labels = array(
        'name'                => _x( 'Destinations', 'Destinations', 'paradises' ),
        'singular_name'       => _x( 'Destination', 'Destination', 'paradises' ),
        'menu_name'           => __( 'Destination', 'paradises' ),
        'parent_item_colon'   => __( 'Parent Destionation', 'paradises' ),
        'all_items'           => __( 'All Destinations', 'paradises' ),
        'view_item'           => __( 'View Destination', 'paradises' ),
        'add_new_item'        => __( 'Add New Destination', 'paradises' ),
        'add_new'             => __( 'New Destination', 'paradises' ),
        'edit_item'           => __( 'Edit Destination', 'paradises' ),
        'update_item'         => __( 'Update Destination', 'paradises' ),
        'search_items'        => __( 'Search destinations', 'paradises' ),
        'not_found'           => __( 'No destinations found', 'paradises' ),
        'not_found_in_trash'  => __( 'No destinations found in Trash', 'paradises' ),
    );

    $args = array(
        'label'               => __( 'destinations', 'paradises' ),
        'description'         => __( 'Destination', 'paradises' ),
        'labels'              => $labels,
        'supports'            => array('title','editor','thumbnail'),
        'taxonomies'          => array('region'),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 100,
        'menu_icon'           => '',
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
    );
    register_post_type('destinations', $args );

}

// Hook into the 'init' action
add_action( 'init', 'paradises_destinations_install', 0 );
4

1 回答 1

0

get_post_type() 函数是获取特定帖子的帖子类型。因此,您需要将参数作为帖子 ID 或帖子对象传递以获取特定帖子的类型。如果您不带参数使用它,它将打印默认的帖子类型,即“帖子”。

于 2013-09-12T11:07:19.253 回答