Skip to main content
added 34 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

I guess you mean overriding the post type of the main search query on the front-end. You could try:

add_action( 'pre_get_posts', function ( WP_Query $q )
{
    if ( 
            ! is_admin() 
         && $q->is_main_query() 
         && $q->is_search()
     )
        $q->set( 'post_type', 'film' );
} );

This way you don't need a secondary search query or mess directly with the globals.

I guess you mean overriding the post type of the main search query on the front-end. You could try:

add_action( 'pre_get_posts', function ( WP_Query $q )
{
    if ( 
            ! is_admin() 
         && $q->is_main_query() 
         && $q->is_search()
     )
        $q->set( 'post_type', 'film' );
} );

This way you don't need a secondary search query.

I guess you mean overriding the post type of the main search query on the front-end. You could try:

add_action( 'pre_get_posts', function ( WP_Query $q )
{
    if ( 
            ! is_admin() 
         && $q->is_main_query() 
         && $q->is_search()
     )
        $q->set( 'post_type', 'film' );
} );

This way you don't need a secondary search query or mess directly with the globals.

Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

I guess you mean overriding the post type of the main search query on the front-end. You could try:

add_action( 'pre_get_posts', function ( WP_Query $q )
{
    if ( 
            ! is_admin() 
         && $q->is_main_query() 
         && $q->is_search()
     )
        $q->set( 'post_type', 'film' );
} );

This way you don't need a secondary search query.