Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. query_posts( array( 'post_type' => array('post', 'portfolio') ) );
  2.  
  3. query_posts('post_type=portfolio');
  4.  
  5. <?php
  6. query_posts(array(
  7. 'post_type' => 'portfolio',
  8. 'showposts' => 10
  9. ) );
  10. ?>
  11. <?php while (have_posts()) : the_post(); ?>
  12. <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
  13. <p><?php echo get_the_excerpt(); ?></p>
  14. <?php endwhile;?>
  15.  
  16. <?php
  17. defined( 'ABSPATH' ) OR exit;
  18. /* Plugin Name: (#6417) "Portfolio" post type in query */
  19.  
  20. add_filter( 'pre_get_posts', 'wpse_6417_portfolio_posts' );
  21. function wpse_6417_portfolio_posts( $query )
  22. {
  23. if (
  24. ! $query->is_main_query()
  25. // Here we can check for all Conditional Tags
  26. OR ! $query->is_archive() // For e.g.: Every archive will feature both post types
  27. )
  28. return $query;
  29.  
  30. $query->set( 'post_type', array( 'post', 'portfolio' ) );
  31.  
  32. return $query;
  33. }
  34.  
  35. add_action( 'pre_get_posts', 'add_custom_post_types_to_loop' );
  36.  
  37. function add_custom_post_types_to_loop( $query ) {
  38.  
  39. if ( is_home() && $query->is_main_query() )
  40.  
  41. $query->set( 'post_type', array( 'post', 'portfolio' ) );
  42.  
  43. return $query;
  44.  
  45. }
  46.  
  47. add_action( 'pre_get_posts', 'cpt_items' );
  48.  
  49. function cpt_items( $query ) {
  50.  
  51. if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'portfolio' ) ) {
  52.  
  53. $query->set( 'posts_per_page', '8' );
  54.  
  55. $query->set( 'order', 'ASC' );
  56.  
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement