WordPress 搜索文章自定义字段 search artilce postmeta

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

厂家CPU内存硬盘流量价格购买链接
RamNode11GB25GB-SSD500GB/mUSD $5购买
Linode11GB25GB-SSD1000GB/mUSD $5购买
DigitalOcean11GB25GB-SSD1000GB/mUSD $5/m购买
Vultr11GB25GB-SSD1000GB/mUSD $5/m购买
腾讯云Qcloud22GB50GB-SSD购买

Posted

in

by

Comments

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注