WordPress: Custom Search

I want to make custom search

This is the output url from the form http://alessandro.host/?country=Italy&area=Milan&type=luxury-hotels

Read More

and this is the explanation:

  • $_GET[‘country’] => this is value from post_meta
  • $_GET[‘area’] => this is value from post_meta
  • $_GET[‘type’] => this is the post category

how i can make this custom search?

Related posts

Leave a Reply

1 comment

  1. I’d check out scribu’s explanation of advanced metadata queries in WordPress 3.1 to help you:
    http://scribu.net/wordpress/advanced-metadata-queries.html

    Also, take a look at WordPress’s documentation on WP_Query:
    http://codex.wordpress.org/Function_Reference/WP_Query

    In your case, it sounds like all you’d need is something like this:

    <?php
    
    $country = $_GET['country'];
    $area = $_GET['area'];
    $type = $_GET['type'];
    
    query_posts( array(
        'category_name' => $type,        
        'meta_query' => array(
            array(
                'key' => 'country',
                'value' => $country,
            ),
            array(
                'key' => 'area',
                'value' => $area,
            )
        )
    ) );
    
    // now do the loop as normal
    
    ?>