【发布时间】:2014-03-05 07:38:44
【问题描述】:
我有一个搜索表单,其中我的表单操作是这样的:
<form action="<?php echo esc_url(home_url('/searched-result')); ?>" method="post">
在搜索结果模板上我有这个查询,
<?php
// Only check these form fields (change the list as needed...)
$fields = array( 'custom_price', 'custom_beds', 'custom_garage');
foreach( $fields as $field ) {
if( $_REQUEST[$field] != '' ) {
// We have something to match, otherwise ignore the field...
$meta_query[] = array(
'key' => $field,
'value' => $_REQUEST[$field], // This is OK, WP_Query will sanitize input!
'compare' => 'LIKE'
);
}
}
$args = array(
'post_type' => 'property_post',
'posts_per_page' => 1000,
'meta_key' => 'SORTFIELD', // The name of the metakey to orderby
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => $meta_query,
);
$query = new WP_Query( $args );
if (have_posts()) : while (have_posts()) : the_post();
?>
<h1 class="title">
<?php the_title(); ?></h1>
【问题讨论】:
-
您的问题还没有解决?
-
yesss........我在做正确的事情来在模板页面上显示搜索结果吗???
-
是的,很高兴听到您的问题得到解决 :)
-
不......我的意思是我的问题没有解决...... :(
-
我可以为多个元值做一个搜索过滤器吗....@Bindiya Patoliya