0

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

0

You 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

  • thanks but it's like my code and not return if $search_query = a part of tag word – ebeliejinfren Nov 16 '18 at 14:05
  • Do you want to apply LIKE search on tags? – Gufran Hasan Nov 16 '18 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.