-
nicole
Hi,
I am using the document library pro plugin by barn2. It uses “documents” that are similar to posts. When I do a search using the search icon it returns the documents on the page instead of the actual page. How can I limit the site search to show only posts and pages? -
Hi there,
you can use the WP
pre_get_posts
hook to change the posttypes returned in the search results using this PHP Snippet:function include_cpt_search( $query ) { if ( !is_admin() && $query->is_main_query() && $query->is_search ) { $query->set( 'post_type', array( 'post', 'page' ) ); } return $query; } add_filter( 'pre_get_posts', 'include_cpt_search' );
This line:
$query->set( 'post_type', array( 'post', 'page' ) );
we set thepost_type
arg in the query to just include thepost
andpage
-
nicole
Worked perfectly! Thanks!
-
Glad to be of help
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.