Reputation: 539
I want to get all products in WooCommerce and make a slider with theme.
So my code in function.php
is:
function zf_theme_home_slide() {
$args = array(
'post_type' => 'product', /* post type */
'post_status' => 'publish', /* post montasher shode */
'orderby' => 'date', /* moratab sazi bar asas tarikh — date , ID , author , type , name , title , parent , rand , comment_count — */
'order' => 'DESC' /* moratabsazi Soudi ya nozooli — DESK = Nozooli , ASC = Soudi */
);
$post_query = new WP_Query( $args );
ob_start();
var_dump( $post_query);
if($post_query->have_posts()) :
?>
<div class="flexslider" >
<ul class="slides">
<?php while ($post_query->have_posts()) :
$post_query->the_post();
// if( get_field('slide_hn_theme') ){
$hn_permalink = get_the_permalink();
$hn_title = get_the_title();
$hn_thumbnail = get_the_post_thumbnail_url();
?>
<li class="product-thumbnail-outer">
<div>
<a class="slide_item" href=" <?php echo $hn_permalink ?> "><img width="300" height="140" src=" <?php echo $hn_thumbnail ?> " />
<span class="slide_items_details">
<span class="slide_item_title"><?php echo $hn_title ?> </span>
<span class="slide_item_creat"> <?php echo $hn_webcreate ?> </span>
</span>
</a>
</div>
</li>
<?php
// }
endwhile;
?>
</ul>
</div>
<?php
endif;
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode('zf_theme_home_slide','zf_theme_home_slide'); /* pro_Des Copy to Page for Show Blogs */
But I only get three products. I don't have any idea that why my code return only three products of all products. How can I fix it?
Upvotes: 0
Views: 164
Reputation: 3514
Try with below code you need to add posts per page limit only..
$args = array(
'post_type' => 'product', /* post type */
'post_status' => 'publish',
'orderby' => 'date',
'posts_per_page' => -1,
'order' => 'DESC'
);
Upvotes: 1