[wp-hackers] 'request' filter for adding custom post types to blog indexes

Krusty Ruffle krustyruffle at rustykruffle.com
Wed Aug 11 18:36:21 UTC 2010


On Wed, Aug 11, 2010 at 2:16 PM, scribu <scribu at gmail.com> wrote:

> That looks just about right. You might also want to check if post_type was
> not already set.
>

So maybe like:

add_filter ( 'request', 'my_request' ) ;
function my_request ( $request ) {
     // Check for proper indexes. An empty $request means we are on the main
blog index.
     if ( empty ( $request ) || isset ( $request['author_name'] ) || isset (
$request['year'] ) ) :
          if ( isset ( $request['post_type'] ) :
                $request['post_type][] = 'my_post_type' ;
          else:
                $request['post_type'] = array ( 'post', 'my_post_type' ) ;
          endif;
     endif;
     return $request ;
}

Or would it be better to do something like:

add_filter ( 'request', 'my_request' ) ;
function my_request ( $request ) {
     // Check for proper indexes. An empty $request means we are on the main
blog index.
     if ( empty ( $request ) || isset ( $request['author_name'] ) || isset (
$request['year'] ) ) :
          $request['post_type'][] = 'post' ;
          $request['post_type'][] = 'my_post_type' ;
     endif;
     return array_unique ( $request ) ;
}


More information about the wp-hackers mailing list