getting posts by tags

时间:2018-11-15 作者:ebeliejinfren

我使用下面的代码通过单词标签获取帖子

$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 根据此代码,它返回具有exactly word标记

EXAMPLE :搜索时“akam它返回带有“akam”标记的帖子,BUT 搜索时“aka“”(a part of word) it返回nothings我想在搜索“aka”时返回所有包含我的arg(“aka”)的标签的帖子,而不仅仅是单词

谢谢

1 个回复
SO网友:Gufran Hasan

您需要将查询修改为:

$search_songs = array(
        \'posts_per_page\' => -1,
        \'post_type\' => \'songs\',
        \'tag\' => $search_query,//use tag to filter posts
    );  

For more details

结束