开发者

Wordpress custom field search

开发者 https://www.devze.com 2023-03-24 20:08 出处:网络
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.

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

精彩评论

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