WordPress, how to make search for posts using get method?

So I am building a WordPress theme for myself to meet my needs, so what I am looking for now is make a search using a get method in php.

If my url is something like this :

Read More
http://www.MyWordPressWebsite.com/search.php?string=Bananas+and+apples

In my search.php I would like to do something like this:

string = $_GET["string"];

 $fruits_args = array(
    'post_type'     => 'fruits',
    'posts_per_page'    => -1,
    'cat'           =>  'fruits'
); 
 $fruits = new WP_Query($fruits_args);

So how do I making the loop related to the string that I get from the the get method ?

comparing the search string the the post type, category and post title would be enough.

Related posts

Leave a Reply

1 comment