开发者

Wordpress custom field search

I want to filter posts with respect to custom fields added to a post.Now I added two custom fields city,zip for each post. I want to filter posts with respect to these two fields. How can write开发者_StackOverflow a custom query for it.

In the where clause I wrote meta_key='City' and meta_value='myval'. It works and returns the post with custom field City and value 'myval'. But I want to check both City and Zip.How can I do that.


I believe you use meta_query for this - just going through an old project now, looks like meta_query can take in an array of filters:

array( 'posts_per_page' => 10,
    'meta_query' => array(
        array('key'=>'key', 'value'=>'value', 'compare'=>'='), 
        array('key'=>'key2', 'value'=>'value2', 'compare'=>'=')
    )
)

Obviously completely untested IRL, but looks like it works from my end.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜