WordPress WP_Query 仅限于 5 个元查询条款 [英] WordPress WP_Query Limited to 5 Meta Query Clauses

查看:50
本文介绍了WordPress WP_Query 仅限于 5 个元查询条款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您更改发布",则查询有效起草"或删除源子句.这些是传递给 WP_Query 构造函数的参数.我立即计算结果以验证 WP_Query 实际上没有返回任何结果.我检查了数据库中的数据并确保数据是一致的.

The query works if you change "publish" to "draft" or remove the source clause. These are args passed to the WP_Query constructor. I immediately count the results to verify that WP_Query is in fact returning no results. I checked the data in the database and made sure the data is congruent.

Array
(
    [post_type] => post
    [post_status] => Array
        (
            [0] => publish
        )

    [meta_query] => Array
        (
            [view_count_clause] => Array
                (
                    [key] => _viewcount
                    [type] => NUMERIC
                )

            [actual_date_clause] => Array
                (
                    [key] => _actualdate
                )

            [start_date_clause] => Array
                (
                    [key] => _actualdate
                    [value] => 2021-03-23 00-00-00
                    [compare] => >
                )

            [end_date_clause] => Array
                (
                    [key] => _actualdate
                    [value] => 2021-03-24 00-00-00
                    [compare] => <
                )

            [color_clause] => Array
                (
                    [key] => _color
                    [type] => NUMERIC
                    [compare] => IN
                    [value] => Array
                        (
                            [0] => 4
                        )

                )

            [source_clause] => Array
                (
                    [key] => _sourcename
                    [value] => AHA
                    [compare] => =
                )

        )

    [orderby] => Array
        (
            [actual_date_clause] => DESC
        )

)

推荐答案

这里有相关问题...... 如何避免WordPress get_posts()中自定义字段(元值)查询的AND条件数量限制?

Related question here.... How to avoid the limit on the number of AND conditions for custom field (meta value) queries in WordPress get_posts()?

问题:

WP_Query 将元查询子句限制为五个元子句.如果您有 6 个元查询子句,您将不会得到任何结果.

WP_Query limits meta query clauses to five meta clauses. If you have 6 meta query clauses, you will get no results.

解决方案 1:

编写您自己的 SQL 查询.相关问题提供的示例.

Write your own SQL query. Example provided by the related question.

解决方案 2:

删除超出 WP_Query 5 个元查询限制的多余元查询并手动过滤结果.要删除的元查询的选择应基于会导致最小数据集的任何内容.

Remove excess meta queries beyond the 5 meta query limit for WP_Query and manually filter results. Choice of meta queries to be removed should be based on whatever would result in the smallest data set.

这篇关于WordPress WP_Query 仅限于 5 个元查询条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆