Guest User

Untitled

a guest
Jun 27th, 2012
220
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sw_custom_post_type_includes($query) {
  2.     // No need to define this. $post_types_list[] = '...'; does the definition by itself
  3.     $post_types_list = array();
  4.     $args = array(
  5.         'public'   => true
  6.     );
  7.     $output = 'names'; // names or objects, note names is the default
  8.     $operator = 'and'; // 'and' or 'or'
  9.     $post_types = get_post_types( $args, $output, $operator );
  10.     // Why looping through the post types array and assigning them to an different array?
  11.     // This way you're just doing $post_types_list = $post_types.
  12.     foreach ( $post_types as $post_type ) {
  13.         $post_types_list[] = $post_type;
  14.     }
  15.     // get_post_types() -> Use the singular as I did: get_post_type(), else you can't search in_array()
  16.     if ( ! is_archive() && ! in_array( get_post_types(), $post_types ) )
  17.         return;
  18.  
  19.     $query->set( 'post_type', $post_types );
  20.     return $query;
  21. }
  22. add_filter('pre_get_posts', 'sw_custom_post_type_includes');
RAW Paste Data