Wordpress自定义帖子类型返回'发布'

时间:2013-09-12 10:13:22

标签: php wordpress

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

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

// 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 );

1 个答案:

答案 0 :(得分:0)

get_post_type()函数是获取特定帖子的帖子类型。因此,您需要将参数作为post id或post对象传递以获取特定帖子的类型。如果您在没有参数的情况下使用它,它将打印默认的帖子类型,即'post'。