1

I have problem with filtering post with tax query.
I have a custom taxonomy called 'actors' and example of the slug is 'david-hasselhoff'. The problem is the post is found when I search with 'david hasselhof', but not with 'david' or 'hasselhof'.

Here is my code so far

$args = [
    'post_type' => 'movies',
    'tax_query' => [
        [
            'taxonomy' => 'actors',
            'field' => 'slug',
            'terms' => $keyword,
        ]
    ]
];
0

You can use below code to search in taxonomy. First using name__like in get_terms it will return all terms ids which have $keyword then that ids use in wp_query.

$termIds = get_terms([
    'name__like' => $keyword,
    'fields' => 'ids'
]);
$args = [
    'post_type' => 'movies',
    'tax_query' => [
        [
            'taxonomy' => 'actors',
            'field' => 'id',
            'terms' => $termIds,
        ]
    ]
];

$query_loop = new WP_Query($args);
|improve this answer|||||

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.