Home » Wordpress » Fetch all products of a category in custom post type in wordpress

Fetch all products of a category in custom post type in wordpress

Posted by: admin November 30, 2017 Leave a comment

Questions:

I am new in wordpress and I am using RT-Theme 15 and I Want to show all

product of custom Post type. When I fetch products all products is not coming

of a particular category. only 9 product is coming out of 15.

here is code whic is showing 9 products:-

<?php
# 
# rt-theme product loop
#
global $args,$wp_query; 

//column

$box_counter = 0;

if(is_tax()) $args = array_merge( $wp_query->query, $args);

query_posts($args); 

$product = array();
$postCount = 0;

if ( have_posts() ) : while ( have_posts() ) : the_post();


?>

    <?php
    //box class

    $product[$postCount]['title']       =   get_the_title();
    $product[$postCount]['thumb']       =   find_image_org_path(get_post_meta($post->ID, THEMESLUG.'product_image_url', true));
    $product[$postCount]['image']       =   @vt_resize( '', $thumb, $w, $h, ''.$crop.'' );
    $product[$postCount]['short_desc']  =   get_post_meta($post->ID, THEMESLUG.'short_description', true);
    $product[$postCount]['permalink']   =   get_permalink();
    $product[$postCount]['watt']        =   get_post_meta($post->ID, 'wpcf-watt', true);    

    $postCount = $postCount + 1;
    ?>

<?php endwhile?>
<?php

    echo "<pre>";print_r($product);



?>

<?php endif; wp_reset_query();?>

But I want to all products into array. I don’t know how to show all products and

where is setting I have to change to show to all products.

Answers:

You can use argument posts_per_page in your query. Set it to -1 and it will fetch all the posts.
So something like this:
$args['posts_per_page'] = -1; query_posts($args);

Questions:
Answers:
  • You can set count use this code in function.php file

    function change_posts_per_page( $query ) 
    {
      $query->set( 'posts_per_page', 5 );
     }
    add_action( 'pre_get_posts', 'change_posts_per_page' );
    

or

  • You can set posts count from admin panel

    1] Go to Dashboard > Setting

    2] Then Reading Settings.

    3] In to that set post count 15.

    4] Then Save Changes

enter image description here