Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

WordPress WP_Query Limited to 5 Meta Query Clauses

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
        )

)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Problem:

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

Solution 1:

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

Solution 2:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...