2017-04-23 6 views
0

特集商品を表示したいが、私の検索結果は何も返されない! 私の製品の1つを特集しましたが、何も表示されませんでした。特集商品を表示しているワードプレス検索

<?php 
    $terms = array(
     "post_type" => "product", 
     "orderby"  => "date", 
     "order"  => "DESC", 
     "posts_per_page" => 12, 
     "meta_query" => array(array('key' => '_featured','value' => 'yes')) 
     ); 
     $query = new WP_Query($terms); 
     while($query->have_posts()){ 
     $query->the_post(); 
     global $product; 
?> 

おかげまた

答えて

0

使用ショートコード[featured_products PER_PAGE = "12" 列= "4"]

またはカスタムロジックとして:ここで

$args = array(
    'post_type' => 'product', 
    'meta_key' => '_featured', 
    'meta_value' => 'yes', 
    'posts_per_page' => 12 
); 

$featured_query = new WP_Query($args); 

if ($featured_query->have_posts()) : 

    while ($featured_query->have_posts()) : 

     $featured_query->the_post(); 

     $product = get_product($featured_query->post->ID); 

     // Output product information here 
     echo "<pre>";print_r($product);echo "</pre>"; 

    endwhile; 

endif; 

wp_reset_query(); // Remember to reset 

文献:http://biostall.com/how-to-display-woocommerce-featureds-product-without-a-shortcode/

+0

おかげでショートコードが機能しましたが、カスタムは機能しませんでした。カスタムタイプを使用しますか?あなたは何か考えていますか? – MusicSara

+0

デバッガを有効にして、完全に形成されたクエリが何であるかを確認してください。http://stackoverflow.com/questions/2473079/how-to-display-all-database-queries-made-by-wordpressまたはhttp://stackoverflow.com/質問/ 2473079/how-to-display-all-database-queries-made-by-wordpress – Senthil

+0

私はこのコードを書いて働きました。当初は、データベース内のどの製品もFeaturedとしてマークされていないため、レコードを取得しませんでした。あなたが欠けていると私はbeleive 1に機能フラグ部分を追加する。任意の製品のクイック編集に移動し、チェックボックスを「おすすめ」とマークします。私はwoocomerceを使って製品を管理しました。これはそれらを特集商品にして、製品オブジェクトを印刷するためのprint_rステートメントがあることを保証する方法です。参照:http://www.modernmarketingpartners.com/set-featured-products-woocommerce/ – Senthil

関連する問題