customization - Get all products with a custom attribute

I want do a custom query to get all products with an especific attribute ("demo" in my case)The query what i

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!

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!

Share Improve this question edited Jun 29, 2015 at 8:26 Karun 1,3471 gold badge9 silver badges22 bronze badges asked Jun 29, 2015 at 7:46 C.B.C.B. 1811 gold badge1 silver badge5 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 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 =

OK I HAVE ALREADY!! yuhuuu!

Thanks a lot guys!!

I have this:

$args = array ( 
     'post_type'  => 'product',
     'posts_per_page'  => -1,
     'meta_query' => array( 
         array( 
          'value' => 'demo', 
          'compare' => 'like'
         ), 
       ),
     ); 

Well this works at least for me

Thanks thanks!!

Best regards!

try something like this

$args = array(
    "post_type" => "product",
    "meta_query" => array(
        array(
            "key"     => "demo",
            "value" => "abc",
            "compare" => "EXISTS",
        ),
    ),
);
$query = new WP_Query( $args );

I know this is old, but straight sql, here are my solutions:

Get all meta data for a product:

SELECT meta_key, meta_value FROM wp_postmeta WHERE wp_postmeta.post_id = 626

Get products with specific meta data

SELECT p.id, p.post_title, m.meta_key, m.meta_value FROM wp_posts p 
INNER JOIN wp_postmeta m ON p.id=m.post_id AND m.meta_key='_auction_dates_to' 

APPEND TO GET META DATA FOR A SPECIFIC PRODUCT

AND p.id=626

Append to get specific meta value

AND m.meta_value='today'

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745311996a4622042.html

相关推荐

  • customization - Get all products with a custom attribute

    I want do a custom query to get all products with an especific attribute ("demo" in my case)The query what i

    4小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信