In regular “query_posts” call includes default post type “post” only, but when you create a custom post type, you may need to call “query_post” for that custom post type only. Suppose you have a custom post type called “product”
So, if you want to run query_posts only for post type product, then use following code:
[code lang=”php”]<?php query_posts( array( ‘post_type’ => ‘product’ ) ); ?>[/code]
Additionally if you want to keep default post types too use:
[code lang=”php”]<?php global $wp_query;
$args = array_merge( $wp_query->query_vars,
array( ‘post_type’ => ‘product’ ) );
query_posts( $args ); ?>[/code]
and finally the loop:
[code lang=”php”]<?php while (have_posts()) :
the_post();
the_title();
the_content( ‘Read the full post »’ );
endwhile; ?>[/code]
But if you want to do it from a plugin without editing theme file, You can modify all main queries before they happen via the pre_get_posts action and a check if is_main_query:
[code lang=”php”]<?php function wpeden_post_type_query( $query ) {
if ( $query->is_main_query() ) {
$query->set( ‘post_type’, array( ‘product’ ) );
}
}
add_action( ‘pre_get_posts’, ‘wpeden_post_type_query’ ); ?>[/code]