我尝试在 woo comm 插件中找到代码(短代码),该插件列出了一个类别中的所有产品的列表,以便能够对其进行修改...1 小时后运气不佳,仍然没有找到。
所以我开始自己编码(重新发明轮子),这是我试图得到的
获取类别 ID="151"中的所有产品,并能够输出名称、永久链接等...
这就是现在的代码,返回所有内容......太多了!我不知道如何过滤它
{
$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;
}
最佳答案
这是我找到的代码,并根据我的需要进行修改
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();
}
?>
关于filter - WooCommerce 自定义循环获取某一特定类别的所有产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15330666/