Skip to content

Instantly share code, notes, and snippets.

@bmodena
Last active November 18, 2015 19:49
Show Gist options
  • Save bmodena/77d80d62d7576a167300 to your computer and use it in GitHub Desktop.
Save bmodena/77d80d62d7576a167300 to your computer and use it in GitHub Desktop.
Wordpress WP_Query Sample of custom post type products
<?php
// Get all products
$args = array(
'posts_per_page' => -1,
'post_type' => 'products',
'orderby' => 'menu_order',
'order' => 'ASC',
'no_found_rows' => true
);
//Set up Objects
$products = new WP_Query($args);
//The loop
if ( $products->have_posts() ) : while ( $products->have_posts() ) : $products->the_post();
// Product loop
get_template_part( 'partials/loops/products' );
endwhile; endif;
//Reset Post data
wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment