No products were found matching your selection.

This error appears only for non-admin users/guests on all category pages. But if I go to some product link directly, I can see the product page and add it to the cart.

I've already tried to change "default sorting" option.

The only way that I've found is to go to "Edit Product" and click "Update" button. Only after this action, this product will appear in shop. But it's not a solution cuz I have a script which import new products time by time and I can't click this button for 10000+ products.


private function createProduct($product, $brand)
        global $wpdb;
        $item = [
            'post_title' => $product['name'],
            'post_status' => 'publish',
            'post_type' => 'product'
        $postId = wp_insert_post($item);

        $meta_keys = [];
        $meta_keys['_visibility'] = 'visible';
        $meta_keys['_stock_status'] = 'instock';
        $meta_keys['wholesale_customer_wholesale_price'] = $product['wholesale_price'];
        $meta_keys['wholesale_customer_have_wholesale_price'] = $product['have_wholesale_price'];
        $meta_keys['_price'] = $product['price'];
        $meta_keys['_regular_price'] = $product['price'];
        $meta_keys['_weight'] = $product['weight'];
        $meta_keys['_sku'] = $product['sku'];
        $meta_keys['_stock'] = $product['stock_quantity'];
        $meta_keys['_manage_stock'] = 'yes';
        $meta_keys['_id_ds'] = $product['id_ds'];
        $meta_keys['_ean'] = $product['ean'];
        $meta_keys['_retail_price'] = $product['retail_price'];
        //$meta_keys['_product_attributes'] = maybe_serialize(wp_unslash($product['attributes']));;

        /* SET Attributes */
        $meta_keys['_product_attributes'] = maybe_serialize(wp_unslash($this->createAttributes($postId, $product['attributes'])));
        /* SET Attributes */

        $custom_fields = [];
        $place_holders = [];
        $query_string = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES ";
        foreach($meta_keys as $key => $value) {
            array_push($custom_fields, $postId, $key, $value);
            $place_holders[] = "('%d', '%s', '%s')";
        $query_string .= implode(', ', $place_holders);
        $wpdb->query($wpdb->prepare("$query_string ", $custom_fields));

        $this->generateFeaturedImage($product['image'], $postId);

        wp_set_object_terms( $postId, 'simple', 'product_type' );
        wp_set_object_terms($postId, get_term_by('name', $brand->name,'product_cat')->term_id, 'product_cat');

        //update_post_meta($postId, '_product_attributes', $product['attributes']);
        return $postId;

closed as off-topic by Krzysiek Dróżdż, Jacob Peattie, Howdy_McGee May 16 '18 at 0:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Probably the problem is that script. What post_status this script applies to the imported products? – Felipe Elia May 9 '18 at 12:35
  • $item = [ 'post_title' => $product['name'], 'post_status' => 'publish', 'post_type' => 'product' ]; $postId = wp_insert_post($item); – Zhi V May 9 '18 at 12:37

WooCommerce products have a lot of metadata. Give a look at this answer to see most of them.

In your case it seems that the problem is the missing _visibility.

Did you already try something like this?

$item = [
    'post_title' => $product['name'],
    'post_status' => 'publish',
    'post_type' => 'product',
$postId = wp_insert_post($item);
update_post_meta( $postId, '_visibility', 'visible' );
  • nah, I pass visibility. – Zhi V May 9 '18 at 12:49
  • Can you please update your answer with the complete code then, @ZhiV? – Felipe Elia May 9 '18 at 12:50
  • Everything was good before, I did some changes in categories and now I can't find the source of problem. – Zhi V May 9 '18 at 13:00
  • Just, admin can see the products and other users can not... – Zhi V May 9 '18 at 13:04
  • It's somehow connected with wholesale plugin – Zhi V May 9 '18 at 14:32

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