php - Wordpress 中的自定义字段搜索
问题描述
我正在寻找一种通过自定义字段过滤我的帖子的方法,例如这个链接:
mywebsite.com/?color:red
查找具有自定义字段名称color
和值的所有帖子red
如果您能帮助我,我将不胜感激,我在互联网上搜索了所有内容,但一无所获。
解决方案
您可以像这样在元查询中使用 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
推荐阅读
- dojo - Dojo2:如何让子小部件实例在其上调用函数
- c# - 使用查询字符串过滤 c# 对象列表
- python - 我不能在 python 中用 matplotlib 关闭()后调用 show()
- angular - 使用 angular4 服务在 POST 请求的标头上设置 cookie
- bash - Bash 脚本编程
- c# - 从字母数字值中查找查询
- r - R中的beg2char函数(qdap包)
- python - Pardot Salesforce Python API
- python-3.x - 无法使用 python 从 redmart 获取产品标题
- javascript - Alert On input Field 在表单中单击 3 次