admin管理员组文章数量:1122832
i use below code for getting posts by word tag
$search_songs = array(
'posts_per_page' => -1,
'post_type' => 'songs',
'tax_query' => array (
array (
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $search_query,
)
)
);
$new_query = new WP_Query( $search_songs );
$search_songs_posts = $new_query->posts;╨
But by this code it return posts that have exactly word tag
EXAMPLE : when search "akam" it return posts that have "akam" tag , BUT when search "aka" (a part of word) it return nothings i want to when search "aka" it return all post that have tags that include my arg("aka") not just exactly word
Thanks
i use below code for getting posts by word tag
$search_songs = array(
'posts_per_page' => -1,
'post_type' => 'songs',
'tax_query' => array (
array (
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $search_query,
)
)
);
$new_query = new WP_Query( $search_songs );
$search_songs_posts = $new_query->posts;╨
But by this code it return posts that have exactly word tag
EXAMPLE : when search "akam" it return posts that have "akam" tag , BUT when search "aka" (a part of word) it return nothings i want to when search "aka" it return all post that have tags that include my arg("aka") not just exactly word
Thanks
Share Improve this question asked Nov 15, 2018 at 12:56 ebeliejinfrenebeliejinfren 1598 bronze badges2 Answers
Reset to default 0You need to modify your query as:
$search_songs = array(
'posts_per_page' => -1,
'post_type' => 'songs',
'tag' => $search_query,//use tag to filter posts
);
For more details
As per document here https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
If you are using tax query it only supports ‘IN’, ‘NOT IN’, ‘AND’, ‘EXISTS’ and ‘NOT EXISTS’.
So if you want to search "aka" and return posts with "akam" tag you need to do this using like query.
You can check this answer for reference : Wordpress tax query use operator LIKE
本文标签: wp querygetting posts by tags
版权声明:本文标题:wp query - getting posts by tags 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736292073a1928857.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论