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
Wordpress按标签名获取帖子_Wordpress - Fatal编程技术网

Wordpress按标签名获取帖子

Wordpress按标签名获取帖子,wordpress,Wordpress,我想按标签name查询帖子,而不是按标签slug $args = array( 'post_type' => "news_type", 'posts_per_page' => -1, 'tag' => "my tag" ); 我已经试过了,但它只适用于tagslug $args = array( 'post_type' => "news_type", 'posts_per_page' => -1, 'tag' => "my tag" ); 另一种方法是通过

我想按标签
name
查询帖子,而不是按标签
slug

$args = array( 'post_type' => "news_type", 'posts_per_page' => -1, 'tag' => "my tag" );
我已经试过了,但它只适用于tag
slug

$args = array( 'post_type' => "news_type", 'posts_per_page' => -1, 'tag' => "my tag" );
另一种方法是通过标记名获取标记,然后从标记中获取slug


(我只能访问代码中的标记名)

实现这一点的最佳方法是使用。您可以将
term\u id
(默认值)、
name
slug
传递给
terms
参数

您可以尝试以下方法:

$args = array(
    'post_type' => 'news_type',
     'posts_per_page' => -1,
    'tax_query' => array(
        array(
            'taxonomy' => 'post_tag',
            'field'    => 'name',
            'terms'    => 'NAME OF THE TAG',
        ),
    ),
);
$query = new WP_Query( $args );

实现这一点的最佳方法是使用一个新的方法。您可以将
term\u id
(默认值)、
name
slug
传递给
terms
参数

您可以尝试以下方法:

$args = array(
    'post_type' => 'news_type',
     'posts_per_page' => -1,
    'tax_query' => array(
        array(
            'taxonomy' => 'post_tag',
            'field'    => 'name',
            'terms'    => 'NAME OF THE TAG',
        ),
    ),
);
$query = new WP_Query( $args );