WooCommerce Custom Loop从一个特定类别获取所有产品 [英] WooCommerce Custom Loop to get all product from one specific category
问题描述
所以我开始编码它自己(重新发明轮子),在这里我试图得到
让我所有产品从类别ID =151,并能够输出名称,永久链接等等等等。
这是现在的代码,返回所有内容。 ..太多了!我不知道怎么过滤它
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'$'$''$ '=>'product',
'posts_per_page'=> 99
);
$ loop = new WP_Query($ args);
if($ loop-> have_posts()){
while($ loop-> have_posts()):$ loop-> the_post();
// echo get_title()。< br />;
var_dump($ loop);
endwhile;
找到并修改我的需求
$ b $ pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ b $ args = array('post_type'=>'product','posts_per_page'=> 10,'product_cat'=> $ atts [0],'orderby'=>'rand');
$ loop = new WP_Query($ args);
echo'< h1 class =upp> Style'。$ atts [0]。'< / h1>';
echo< ul class ='mylisting'>;
while($ loop-> have_posts()):$ loop-> the_post();
global $ product;
$ b $ echo'< li>< a href ='。get_permalink()。'>'get_the_post_thumbnail($ loop-> post-> ID,'thumbnail')。 '< / A>< /立GT;';
endwhile;
echo< / ul>;
wp_reset_query();
}
?>
I try to find the code (short code) in the woo comm plugin that made the list of all the product from one category, to be able to modify it... no luck after 1 hours, still no find.
So i start coding it myself (reinventing the wheel) and here what i try to get
get me all the product from category ID="151" and be able to output the name, the permalink etc etc...
this is the code now, that return everything.... way too much ! and i don't know how to filter it
{
$args = array(
'post_type' => 'product',
'posts_per_page' => 99
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
//echo get_title()."<br/>";
var_dump($loop);
endwhile;
}
here is the code i have found, and modify to my needs
function get_me_list_of($atts, $content = null)
{
$args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'product_cat' => $atts[0], 'orderby' => 'rand' );
$loop = new WP_Query( $args );
echo '<h1 class="upp">Style '.$atts[0].'</h1>';
echo "<ul class='mylisting'>";
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
echo '<li><a href="'.get_permalink().'">'.get_the_post_thumbnail($loop->post->ID, 'thumbnail').'</a></li>';
endwhile;
echo "</ul>";
wp_reset_query();
}
?>
这篇关于WooCommerce Custom Loop从一个特定类别获取所有产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!