Guest User

Untitled

a guest
Dec 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. // Modify the default loop, include custom post types
  2. global $wp_query;
  3. $args = array_merge( $wp_query->query, array( 'post_type' => 'any' ) );
  4. query_posts( $args );
  5.  
  6. // The beginning of the loop looks like this:
  7. while ( have_posts() ) : the_post();
  8.  
  9. $args = array_merge( $wp_query->query, array( 'post_type' => array('post','news','essays') ) );
  10.  
  11. add_action( 'pre_get_posts', 'add_my_custom_post_type' );
  12. /**
  13. * @param WP_Query $query
  14. * @return WP_Query
  15. */
  16. function add_my_custom_post_type( $query ) {
  17. if ($query->is_main_query())
  18. $query->set( 'post_type', array( 'post', 'page', 'any_custom_type' ) );
  19. return $query;
  20. }
  21.  
  22. add_action('pre_get_posts', 'add_my_custom_post_type');
  23.  
  24. /**
  25. * @param WP_Query $query
  26. * @return WP_Query
  27. */
  28. function add_my_custom_post_type($query) {
  29. if(
  30. empty($query->query['post_type'])
  31. or $query->query['post_type'] === 'post'
  32. ){
  33. $query->set('post_type', array('post', 'my_custom_type'));
  34. }
  35. }
  36.  
  37. and !is_admin()
  38.  
  39. add_action('pre_get_posts', 'add_my_custom_post_type');
  40.  
  41. /**
  42. * @param WP_Query $query
  43. * @return WP_Query
  44. */
  45. function add_my_custom_post_type($query) {
  46. if(
  47. empty($query->query['post_type'])
  48. or $query->query['post_type'] === 'post'
  49. and !is_admin()
  50. ){
  51. $query->set('post_type', 'any');
  52. }
  53. }
Add Comment
Please, Sign In to add comment