Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sw_custom_post_type_includes($query) {
- // No need to define this. $post_types_list[] = '...'; does the definition by itself
- $post_types_list = array();
- $args = array(
- 'public' => true
- );
- $output = 'names'; // names or objects, note names is the default
- $operator = 'and'; // 'and' or 'or'
- $post_types = get_post_types( $args, $output, $operator );
- // Why looping through the post types array and assigning them to an different array?
- // This way you're just doing $post_types_list = $post_types.
- foreach ( $post_types as $post_type ) {
- $post_types_list[] = $post_type;
- }
- // get_post_types() -> Use the singular as I did: get_post_type(), else you can't search in_array()
- if ( ! is_archive() && ! in_array( get_post_types(), $post_types ) )
- return;
- $query->set( 'post_type', $post_types );
- return $query;
- }
- add_filter('pre_get_posts', 'sw_custom_post_type_includes');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement