Search Box Filter via pre_get_posts
-
I can’t work out what is wrong with this code – is_page(61) equates to true (by itself) and it works as desired if I take out the is_page(61)
//* Add search box to specific page sidebars add_action( 'pre_get_posts', 'wt_pre_get_posts_nav_search' ); //------------------------------- function wt_pre_get_posts_nav_search($query) { //Use CPT mediaReleases if page is Media Releases if (is_page( 61 )) { //if Media Releases Page if ($query->is_search && !is_admin() ) { $query->set('post_type', 'mediaReleases'); } } }
Or I tried this
//* Add search box to specific page sidebars add_action( 'pre_get_posts', 'wt_pre_get_posts_nav_search' ); //------------------------------- function wt_pre_get_posts_nav_search($query) { //Use CPT mediaReleases if page is Media Releases if ($query->is_page( 61 ) && $query->is_search && !is_admin() ) { $query->set('post_type', 'mediaReleases'); } }
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Search Box Filter via pre_get_posts’ is closed to new replies.