首页 > 解决方案 > 帖子类型有多个单词时查询wordpress自定义帖子类型

问题描述

我有一个custom post type名字What We Do注册如下,

function cp_what_we_do() {
    register_post_type('What We Do', array(
        'labels' => array(
            'name' => 'What We Do',
            'singular_name' => 'wwd',
            'add_new_item' => 'Add New Item',
            'edit_item' => 'Edit WWD Item',
        ),
        'description' => 'What We Do',
        'public' => true,
        'menu_position' => 20,
        'supports' => array('title','editor')
    ));
}

add_action('init', 'cp_what_we_do');

我查询上面的自定义帖子,例如,

$args = array(
            'numberposts' => -1,
            'post_type'   => 'What We Do',
            'order'       => 'ASC',
            'post_status'=>'publish',
            'posts_per_page' => $countNo
        );
$the_query = new WP_Query($args);

上面的查询返回No Posts。但是相同的过程适用于帖子类型services,并且效果很好。当我对post_type( What We Do) 有多个单词时,查询不返回任何值。请有人详细说明这个问题。

标签: wordpresswordpress-themingcustom-post-type

解决方案


推荐阅读