WordPress 搜索文章自定义字段 search artilce postmeta
WordPress 插件开发中,有时需要检索文章对应的自定义字段postmeta,这里写一下相关的代码段 $s…
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
类别:WordPress教程、 
		本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!