WordPress 插件开发中,有时需要检索文章对应的自定义字段postmeta,这里写一下相关的代码段
$searchArgs = array(
'post_type' => 'post',
'meta_query' = array(
'relation' => 'AND',
array( 'key' => 'srch_age', 'value' => $_REQUEST['srch_age'] ),
array( 'key' => 'srch_ptype', 'value' => $_REQUEST['srch_ptype'] )
// ... Add as many other criteria as you need
)
);
query_posts( $searchArgs );
while( have_posts() ): the_post();
...
endwhile;
官方文档:https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters