Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从自定义帖子类型Wordpress的类别获取帖子_Php_Wordpress_Categories_Custom Post Type - Fatal编程技术网

Php 从自定义帖子类型Wordpress的类别获取帖子

Php 从自定义帖子类型Wordpress的类别获取帖子,php,wordpress,categories,custom-post-type,Php,Wordpress,Categories,Custom Post Type,我有下面的代码,用于创建一个类别。如何使用此类别获取帖子?我可以获取该类别的id,但无法获取该类别的所有帖子 function create_taxonomy() { $labels= array( 'name' => 'Kategórie', 'singular_name' => 'Kategórie', 'search_items' => 'Vyhladať kategórie', 'all_items' => 'Všetky

我有下面的代码,用于创建一个类别。如何使用此类别获取帖子?我可以获取该类别的id,但无法获取该类别的所有帖子

function create_taxonomy()
{
    $labels= array(
    'name' => 'Kategórie',
    'singular_name' => 'Kategórie',
    'search_items' => 'Vyhladať kategórie',
    'all_items' => 'Všetky kategórie',
    'edit_item' => 'Upraviť',
    'update_item' => 'Aktualizovať',
    'add_new_item' => 'Pridať',
    'new_item_name' => 'Nový názov',
    'menu_name' => 'Kategórie',
    );
    register_taxonomy('Categories', array('service'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array('slug' => 'categories')
    ));
}
add_action('init','create_taxonomy',0);
这是邮政类型


下面的代码应该可以做到这一点

$args = array(
    'post_type' => 'post',
    'tax_query' => array(
        array(
            'taxonomy' => 'categories',
            'field' => 'slug', //can be set to ID
            'terms' => 'category-slug' //if field is ID you can reference by cat/term number
        )
    )
);
$query = new WP_Query( $args );
将“分类法”设置为您的类别分类法,并将术语更改为您的类别名称。
如果要按类别ID执行此操作,请将字段值更改为“term_ID”,并在terms值中提供类别ID。

找到该类别的ID,并在get_posts函数中使用“Category”参数。医生:我不知道如何获得自定义帖子类型,我可以获得经典帖子