Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Anyone know of an easy way to alter the default WordPress search from searching ALL pages, to searching only child pages from a specific page parent?

I know of the filter you can use to alter whether pages or posts are searched:

function SearchFilter($query) {
if ($query->is_search) {
    $query->set('post_type', 'page');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');

Maybe there is a way to add further information here to specify a particular page parent?

share|improve this question
add comment

1 Answer 1

I have no idea if this will work, but couldn't you reference the post_parent in the query args?

function SearchFilter($query) {
if ($query->is_search) {
    //$query->set('post_type', 'page');
    global $post;
    $query->set( 'post_parent', $post->ID );
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');

Again, completely untested. I'm not terribly familiar with using $query->set().

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.