• Even though it’s bringing up a post, it’s not bring up more than one. I have more than one post, but only 1 shows up, but not more than that. What’s happening?

    <?php
        query_posts( array ( 'post_type' ='product', 'product_cat' = 'newly-released', 'post_per_page' = 4 ) );
    while (have_posts()) : the_post();
    <h2><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h2>
          <a href="<?php the_permalink() ?>"><?php echo get_the_post_thumbnail(); ?></a><?php the_excerpt(); ?>
    <hr/>
    endwhile;
    wp_reset_query();
    ?>
Viewing 10 replies - 1 through 10 (of 10 total)
  • You could add a url parameter for posts per page. Something like this:

    <?php
    $page = ( get_query_var( 'posts_per_page' ) == 'all' ) ? -1 : 45;
    query_posts( array(
         'post_type' ='product',
          'product_cat' = 'newly-released',
        'posts_per_page' => $page
    ) );
    while (have_posts()) : the_post();
    ?>
    <h2><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h2>
          <a href="<?php the_permalink() ?>"><?php echo get_the_post_thumbnail(); ?></a><?php the_excerpt(); ?>
    <hr/>
    <?php
    endwhile;
    wp_reset_query();
    ?>

    Thread Starter Judia

    (@judia)

    Still the same problem. Does it help to know that I’m using woocommerce?

    So you are looking to display your latest WooCommerce products, not posts.
    You have set the query parameters array to include the post_type to grab products which is correct, so to display all post (product) you must set up parameter posts_per_page from ‘post_per_page’ = 4 to 'posts_per_page' => -1
    My first line have -1 and post type product in it, so i dont undestand why that didnt work for you

    Thread Starter Judia

    (@judia)

    I already tried the -1 and it did nothing.

    try this and tell me if you see something, don`t put your category in array $args. you must see al the product no matter in which category they are.

    <?php
            $args = array( 'post_type' => 'product', 'posts_per_page' => -1,  );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
                        <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
    
                            <?php woocommerce_show_product_sale_flash( $post, $product ); ?>
    
                            <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />'; ?>
    
                            <h3><?php the_title(); ?></h3>
    
                            <span class="price"><?php echo $product->get_price_html(); ?></span>                    
    
                        </a>
    
                        <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
    
        <?php endwhile; ?>
        <?php wp_reset_query(); ?>
    Thread Starter Judia

    (@judia)

    I still have this problem. I don’t know what’s happening. I’ve tried EVERYTHING.

    Thread Starter Judia

    (@judia)

    I’ve disabled every single plugin I have, except woocommerce and it still happens.

    Moderator keesiemeijer

    (@keesiemeijer)

    Hi Judia

    Is the one post that shows up a post from the post type ‘product’?
    Please post the code you’re using now.

    swayam.tejwani

    (@swayamtejwani)

    I have more than one post

    You need posts (Default WP POST) or products (Post type Product) ??, the code which you are using is for fetching woocommerce product and not default posts.

    Thread Starter Judia

    (@judia)

    I need to fetch products.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Query not working properly?’ is closed to new replies.