在页面模板中创建过滤器

时间:2014-09-30 19:11:22

标签: wordpress wordpress-theming

我正在使用Realto主题进行wordpress我想知道我是否在正确的道路上。我需要显示一个城市的属性。所以我决定创建一个页面模板来添加位置

这是默认参数,但我不知道如何按城市过滤结果

$args = array(
        'numberposts'     => '',
        'posts_per_page' => $posts_per_page,
        'offset'          => 0,
        'cat'        =>  '',
        'orderby'         => 'date',
        'order'           => 'DESC',
        'include'         => '',
        'exclude'         => '',
        'meta_key'        => '',
        'meta_value'      => '',
        'post_type'       => 'property',
        'post_mime_type'  => '',
        'post_parent'     => '',
        'paged'             => $paged,
        'post_status'     => 'publish'
    );

我尝试添加

'locations' => 'MYCITY'

但它没有用

这是我按城市搜索时的搜索结果示例,因此我的观点基于此。

/?post_type=property&search_keyword=&locations=MYCITY&property_type=proyectos&beds=&baths=&status=&min-price=&max-price=

1 个答案:

答案 0 :(得分:0)

我认为locations是自定义字段?也许这有效:

<?php
$args = array(
    'post_type'  => 'property',
    'meta_key' => 'locations',
    'meta_value' => 'MYCITY'
);

?>

访问http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters了解详情。