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" );
我已经试过了,但它只适用于tagslug
$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 );