calling product category by loop

On the front page of the site I would like to get all the products in one category and display the product name, price and order quantity box (so that a user can order as many bottles of wine as they like) but I am unsure how to call all get all products from a category. The website is a one page site and the is also running the wp-loop on the same page so there would need to be no conflicts there

Is there documentation somewhere where I can find how to call products from a category? call the product price? call a quantity box?

  • nathanshanahan

    Thanks,

    Im not sure shortcodes are going to help me here. I tried the implementation you suggested and while I was able to call the products successfully by category I'm having a conflict with my the blog loop which also runs on the same page.

    I have the following code working without interfering with the blog:

    <?php

    // The Query
    $the_query = new WP_Query( $args );

    // The Loop
    $args = array( 'post_type' => 'product', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <article class="purchase_wine">
    " rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h3>
    </article>

    <?php endwhile; ?>

    <?php wp_reset_postdata(); ?>`

    but what I would like to know is how to modify this so that it:
    1.) calls all the products by the category slug
    2.) displays the product with the option to enter a quantity that you wish to buy (i.e - not the add to cart button but a enter quantity button.

    the second being my biggest hurdle to overcome

    Any assistance would be greatly appreciated.

  • Aaron

    As you can't use a shortcode, you'll want to use the related template function in your index.php or home.php template file.

    *
     * function mp_list_products
     * Displays a list of products according to preference. Optional values default to the values in Presentation Settings -> Product List
     *
     * @param bool $echo Optional, whether to echo or return
     * @param bool $paginate Optional, whether to paginate
     * @param int $page Optional, The page number to display in the product list if $paginate is set to true.
     * @param int $per_page Optional, How many products to display in the product list if $paginate is set to true.
     * @param string $order_by Optional, What field to order products by. Can be: title, date, ID, author, price, sales, rand
     * @param string $order Optional, Direction to order products by. Can be: DESC, ASC
     * @param string $category Optional, limit to a product category
     * @param string $tag Optional, limit to a product tag
     */
    mp_list_products( $echo = true, $paginate = '', $page = '', $per_page = '', $order_by = '', $order = '', $category = '', $tag = '' )

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.