Open PeterX29 opened 6 years ago
We cannot change tags searching behavior, cause it is responsibility of wordpress rest api. I can suggest you theese modification of your code:
if (tags.Count() == 0 || tags.Any(t => t.Name == t[i].Name)) //If none in DB or not exactly match
{
...
}
may be @ThomasPe see another convinient methods
Someone sugested to use the inherit from TagsQueryBuilder:
public class ExtendedTagsQueryBuilder : TagsQueryBuilder
{
[QueryText("exact")]
public bool Exact { get; set; }
}
And specify this parameter:
ExtendedTagsQueryBuilder queryBuilder = new ExtendedTagsQueryBuilder();
queryBuilder.Exact = true;
queryBuilder.Search = t[i].Name;
...works great :)
Interesting thing. There is no information about 'exact' field in official WP REST API docs. @ThomasPe I think, we should include this in our lib, but I cannot find any info about this field and in which endpoints it can be used
I agree we should add this if it's an API feature. Mabye we can add it for Tags for now and do some research if this applies to other entities as well.
I have one array of tags and need to check if the tag already exists in database.
The below code works well, however , "queryBuilder.Search = t[i].Name" works the same way as the LIKE in SQL. I mean, if I have too similar tags, ex "first tag is the best" and "first tag" ig get error.
How to use the queryBuilder.Search to get exact match?