WordPress.org

Support

Support » How-To and Troubleshooting » Restrict search results to specific pages using array variable?

Restrict search results to specific pages using array variable?

  • Hello,

    I’m restricting my search function using a filter similar to this:

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

    What I’m trying to do is limit the search to certain pages. I have the IDs of these pages stored in a global variable from a different function ($page_array), so I know I shouldn’t have to list all of the page IDs in another array, like this:

    $query->set('ID', array(52, 33, 45, etc));

    But I can’t figure out how to pass the $page_array variable to the filter function. I’m feeling syntactically challenged. Any assistance is greatly appreciated.

  • The topic ‘Restrict search results to specific pages using array variable?’ is closed to new replies.
Skip to toolbar