As you’ve already get results with tag I’m going to give suggestion only for address and rating.
For your current situation, the best option is to use WordPress post meta to store these values. Then you can use meta query to retrieve those posts.
$args = array(
'post_type' => 'hotel',
'meta_query' => array(
array(
'key' => 'address',
'value' => $adr,
'compare' => 'LIKE',
),
),
);
$query = new WP_Query( $args );
For rating
$args = array(
'post_type' => 'hotel',
'meta_query' => array(
array(
'key' => 'rating',
'value' => $rating,
'compare' => '>',
),
),
);
$query = new WP_Query( $args );
EDIT
You can combine the meta queries in a single query like this
$args = array(
'post_type' => 'hotel',
'relation' => 'AND'
'meta_query' => array(
array(
'key' => 'address',
'value' => $adr,
'compare' => 'LIKE',
),
array(
'key' => 'rating',
'value' => $rating,
'compare' => '>',
),
),
);
$query = new WP_Query( $args );
You can also choose OR
relationship if you want between the meta queries.
whenever get_search_form()
is called, the content of searchform.php
is included. This is the default search page. If you want to keep that search option, you should include this code in some place else. Maybe in another file and include it where you want to display your custom search option.
That being said, your main problem is how to receive the passed values. As you are using GET
method, you’d use $_GET['adr']
to receive the value after the form has been submitted. But you should change name post_type
and tag
to something else as they are wordpress built-in query var.
EDIT
You are saving post meta as array. Don’t do that. Save them separately. Save it such that, you get address by $adr = get_post_meta($post_id, 'adr', true);
and rating by $dvoi = get_post_meta($post_id, 'dvoi', true);
Your metabox code should be
<input type="text" id="adr" value="<?php echo $adr; ?>" name="adr" size="40" />
<input type="text" id="dvoi" value="<?php echo $dvoi; ?>" name="dvoi" size="40" />
Here’s the meta query to display posts that have rating equal $voiture
OR address like $adresses
AND contain tag $tag.
$args = array(
'tag' => $tag,
'post_type' => 'hotels',
'posts_per_page' => 3,
'relation' => 'OR',
'meta_query' => array(
array(
'key' => 'adr',
'value' => $adresses,
'compare' => 'LIKE'
),
array(
'key' => 'dvoi',
'value' => $voiture,
'compare' => '='
)
)
);
$wp_querysearch = new WP_Query( $args );