2017-06-13 4 views
0

カスタムクエリを作成する必要があります。すべての製品は、各製品のすべてのイメージ、メタおよびすべての "高度なカスタムフィールド" acfを使用してjsonフォーマットのクエリに適合します。wooocommerceからのフィルタリングされた製品のリスト

I部分的に次のコードを使用して成功する:

function get_woocommerce_product_list($request) { 
    $query = array(
     'post_type' => 'product', 
     'posts_per_page' => -1, 
     'meta_query' => array(
      array(
       'key' => '_vendor', 
       'value' => 'farsi', 
      ), 
     ) 
    ); 

    $result = []; 
    $wp_query = new WP_Query($query); 

    foreach ($wp_query->posts as $post) { 
     $result[$post->ID]['product'] = $post; 
    } 

    return $result; 
} 

任意の助けを?

私はコードの先頭部分が細かいですが、私のようなものに以下のコードを変更すると思う

答えて

0

$wp_query = new WP_Query($query); 
$result = array(); 

if ($wp_query->have_posts()) { 

while ($wp_query->have_posts()) { 
$wp_query->the_post(); 

    $result[] = array(
    'product_name' => get_the_title(), 
    'price' => get_post_meta(get_the_ID(), '_regular_price', true), 
    //find rest of values you require and put them into the array here 
); 

} 
} 

$json_result = json_encode($result); 
return $json_result; 
関連する問題