WordPress.org

Ready to get started?Download WordPress

Forums

Restrict search results to specific pages using array variable? (1 post)

  1. yarnboy
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.