Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Modify the default loop, include custom post types
- global $wp_query;
- $args = array_merge( $wp_query->query, array( 'post_type' => 'any' ) );
- query_posts( $args );
- // The beginning of the loop looks like this:
- while ( have_posts() ) : the_post();
- $args = array_merge( $wp_query->query, array( 'post_type' => array('post','news','essays') ) );
- add_action( 'pre_get_posts', 'add_my_custom_post_type' );
- /**
- * @param WP_Query $query
- * @return WP_Query
- */
- function add_my_custom_post_type( $query ) {
- if ($query->is_main_query())
- $query->set( 'post_type', array( 'post', 'page', 'any_custom_type' ) );
- return $query;
- }
- add_action('pre_get_posts', 'add_my_custom_post_type');
- /**
- * @param WP_Query $query
- * @return WP_Query
- */
- function add_my_custom_post_type($query) {
- if(
- empty($query->query['post_type'])
- or $query->query['post_type'] === 'post'
- ){
- $query->set('post_type', array('post', 'my_custom_type'));
- }
- }
- and !is_admin()
- add_action('pre_get_posts', 'add_my_custom_post_type');
- /**
- * @param WP_Query $query
- * @return WP_Query
- */
- function add_my_custom_post_type($query) {
- if(
- empty($query->query['post_type'])
- or $query->query['post_type'] === 'post'
- and !is_admin()
- ){
- $query->set('post_type', 'any');
- }
- }
Add Comment
Please, Sign In to add comment