I was wondering if there was a way how to filter product variations by titles using WP query. For example if we wish to delete only certain product variations from all products that are accepted by the filter condition.

So far, I put together the following filter, but it does not work well.

Any suggestions how to go through all variable products and target product variation titles having dashed phrase "cena-za-1-bezny-metr" in the name?

            case 'trash_unwanted_variations':
                $args = array(
                    'post_type' => 'product_variation',
                    'no_found_rows' => true,
                    'ignore_sticky_posts' => true,
                    'fields' => 'ids',
                    'posts_per_page' => -1,
                    'orderby' => 'name',
                    'order' => 'asc',
                    's' => get_search_query(),
                    'title' => array(
                            'value' => sanitize_title_with_dashes('cena-za-1-bezny-metr'),
                            'compare' => 'IN',

Your Answer

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

Browse other questions tagged or ask your own question.