WordPress.org

Support

Support » Plugins and Hacks » Hacks » Make search only search children of a specific page

Make search only search children of a specific page

  • Hello,
    I have a Wiki section on my site, and I want to modify WordPress’s native search to only search pages in this Wiki, or in other words, only children of page #278.
    I’ve succeeded in listing children pages of a given page with wp_list_pages and the parameter ‘child_of’, so I’ve been trying for something like that. Two attempts so far:
    In the search page…

    <?php if ( have_posts(array('child_of'=>278)) ) : ?>
    ...
    <?php while ( have_posts(array('child_of'=>278)) ) : the_post(array('child_of'=>278)) ?>

    And alternatively in my functions file…

    function SearchWikiPages($query) {
    	if ($query->is_search) {
    		$query->query_vars['child_of']=278;
    	}
    	return $query;
    }
    add_filter('pre_get_posts','SearchWikiPages');

    So far with no luck. If anyone knows how I can do this please help. I would not be opposed to using a plugin, or any other creative solution if it gets what I need.
    Thanks!

  • The topic ‘Make search only search children of a specific page’ is closed to new replies.
Skip to toolbar