使用自定义字段搜索页面


Search pages using custom fields

我已经被这个问题困扰了一个星期了。我想创建一个搜索栏,将显示与自定义字段中填写的数据页面的列表。例如,如果我选择"Pre Owned"作为搜索栏的状态,它应该显示具有自定义字段的页面,其中元数据是"Pre Owned"。我完全不知道该怎么做。我知道可以在自定义帖子中搜索,但我想在页面中搜索。http://jaroyachting.com/dev/yacht-list/是列表的样子

这个代码是我试过的,不工作。$searchYachts是我如何调用元数据

if(isset($_POST['filter'])) {
global $wp_query; // get the global object
$searchYachts = get_post_meta( $page->ID, 'yachtinfo', true );
$thesearch = get_search_query(); // get the string searched
// merge them with one or several meta_queries to meet your demand
$args = array_merge( $wp_query->query, array( 
   'meta_query' => array(
    array(
        'key' => $searchYachts["status"],
        'value' => $_POST['status'],
        'compare' => 'IN'
    )
)
    ));
query_posts( $args ); // alter the main query to include your custom parameters

提前感谢!

在此元查询中,您可以传递元值

$args = array(
   'meta_query' => array(
       array(
           'key' => 'cp_annonceur',
           'value' => 'professionnel',
           'compare' => '=',
       )
   )
);
$query = new WP_Query($args);

这就是我所能做到的。但是现在它显示每一页…

if(isset($_POST['filter'])) {
$status = $_POST['status'];
$args = array(
   'meta_query' => array(
       array(
       'key' => 'status',
       'value' => '$status',
       'compare' => '=',
       )
    )
);
$property_query = new WP_Query($args);
?>                  <div id="pages">
<?php $pages = get_pages(array($property_query)); ?>
<ul style="list-style:none;">
    <?php foreach ($pages as $page): ?>
       <div id="schip"> <li>
            <div id="fotoSchip"><?php echo '<a href="' . get_page_uri($page)     .'">' . get_the_post_thumbnail($page->ID, array( 365, 230)) . '</div>
<div id="infoSchip"><h5>' . $page->post_title; ?></h5></a>
        <?php 
        $yacht = get_post_meta( $page->ID, 'yachtinfo', true ); 
                            foreach( $yacht as $list){
                                echo '<div id="statusSchip">' .     $list['status'] . '</div>';
                                    echo '<div id="prijsSchip">Price: ' .     $list['price'] . '</div>';
                                }
endforeach;

}