I want do a custom query to get all products with an especific attribute (“demo” in my case)
The query what i want returns from this:

a:5:{s:4:"demo";
a:6:{s:4:"name";
    s:4:"DEMO";
    s:5:"value";
    s:366:"LINK TO DEMO";
    s:8:"position";
    s:1:"0";
    s:10:"is_visible";
    i:0;
    s:12:"is_variation";
    i:0;
    s:11:"is_taxonomy";
    i:0;
}

}

I don’t know how do an $args to get products. I want $args be something like this:

    $args = array ( 
         'meta_query' => array( 
             array( 
              'key' => 'meta_value', 
              'value' => 'demo', 
              'compare' => 'LIKE', ), 
           ), 
   );

Thanks!

4 s
4

You have written key as meta_value. It should be your meta name. The name you have given to your custom fields or meta. Then use the following query.

$args = array ( 
         'post_type'  => 'your-post-type',
         'posts_per_page'  => -1,
         'meta_query' => array( 
             array( 
              'key' => 'demo', 
              'value' => '',
              'compare' => '!='
             ), 
           ), 
   );

By default the compare is set to =

Leave a Reply

Your email address will not be published. Required fields are marked *