Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- query_posts( array( 'post_type' => array('post', 'portfolio') ) );
- query_posts('post_type=portfolio');
- <?php
- query_posts(array(
- 'post_type' => 'portfolio',
- 'showposts' => 10
- ) );
- ?>
- <?php while (have_posts()) : the_post(); ?>
- <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
- <p><?php echo get_the_excerpt(); ?></p>
- <?php endwhile;?>
- <?php
- defined( 'ABSPATH' ) OR exit;
- /* Plugin Name: (#6417) "Portfolio" post type in query */
- add_filter( 'pre_get_posts', 'wpse_6417_portfolio_posts' );
- function wpse_6417_portfolio_posts( $query )
- {
- if (
- ! $query->is_main_query()
- // Here we can check for all Conditional Tags
- OR ! $query->is_archive() // For e.g.: Every archive will feature both post types
- )
- return $query;
- $query->set( 'post_type', array( 'post', 'portfolio' ) );
- return $query;
- }
- add_action( 'pre_get_posts', 'add_custom_post_types_to_loop' );
- function add_custom_post_types_to_loop( $query ) {
- if ( is_home() && $query->is_main_query() )
- $query->set( 'post_type', array( 'post', 'portfolio' ) );
- return $query;
- }
- add_action( 'pre_get_posts', 'cpt_items' );
- function cpt_items( $query ) {
- if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'portfolio' ) ) {
- $query->set( 'posts_per_page', '8' );
- $query->set( 'order', 'ASC' );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement