首页 > 解决方案 > Wordpress 中的自定义字段搜索

问题描述

我正在寻找一种通过自定义字段过滤我的帖子的方法,例如这个链接:

mywebsite.com/?color:red

查找具有自定义字段名称color和值的所有帖子red

如果您能帮助我,我将不胜感激,我在互联网上搜索了所有内容,但一无所获。

标签: phpwordpresssearchcustom-fields

解决方案


您可以像这样在元查询中使用 ACF 字段:

$posts = get_posts(array(
    'numberposts'   => -1,
    'post_type'     => 'post',
    'meta_key'      => 'color',
    'meta_value'    => 'red'
));

ACF 文档中有更多示例: https ://www.advancedcustomfields.com/resources/query-posts-custom-fields/#custom-field%20parameters


推荐阅读