I am using the below to search to check if a product category is already created

$params = [
    'search' => "category1"
$searchedparaCat = $woocommerce->get('products/categories', $params);

using https://github.com/woocommerce/wc-api-php

This works however it seems to do searches as 'like' instead of absolute. For example the above could return

"category11", "category14", "category14552"....

What I need really is an absolute search so that it will ONLY return a category with the give search term as its slug. Is this possible? I know I can iterate over the returned results and filter them but before I go down that route can this be done via the api?


Searches are always fuzzy, not exact. You might be looking for the slug parameter here. From the documentation, it reads Limit result set to resources with a specific slug.

I assume it should fit your case and it would only return the categories that match the slug provided.

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.