get_posts () und WP_query begrenzen “AND” -Bedingungen auf maximal 6 für Metawertabfragen in WordPress

Die function get_posts() und WP_query in WordPress beschränkt mich auf maximal 6 AND Bedingungen für Meta-Wert-Abfragen. Kann ich get_posts() zwingen, mit mehr als 6 AND Bedingungen zu arbeiten?

Im Folgenden finden Sie ein Beispiel für meine Abfrage, die ein leeres Array zurückgibt.

Der folgende Code 1 ist die print_r() des Arrays, die ich an get_posts () übergebe, was zu einem leeren Array führt, das von get_posts() . Hinweis Ich habe mehrere Kombinationen von AND Abfragen ausprobiert – dies ist nur ein Beispiel.

Code 2 unten ist identisch mit Code 1, aber ich habe eine AND statement entfernt und gibt ein Ergebnis zurück.

Um Zweifel zu vermeiden, habe ich auch ein Beispiel für ein Post-Detail in meiner database (als Code 3 unten) eingefügt, das mit der Abfrage in Code 1 übereinstimmen sollte.

Code 4: zeigt das sql, das von WP_query zurückgegeben wird, wenn ich das Array direkt an es übergebe. Es gibt auch ein leeres Array zurück, wenn ich mehr als 7 AND Bedingungen verwende

Code 1:

 Array ( [post_type] => page [posts_per_page] => 10000 [category_name] => active-cards [meta_query] => Array ( [relation] => AND [0] => Array ( [key] => card_purchase_rate [value] => Array ( [0] => 0 [1] => 46 ) [compare] => BETWEEN [type] => NUMERIC ) [1] => Array ( [key] => card_balance_transfer_rate [value] => Array ( [0] => 0 [1] => 14 ) [compare] => BETWEEN [type] => NUMERIC ) [2] => Array ( [relation] => AND [0] => Array ( [key] => is_rewards_card [value] => yes [compare] => LIKE ) [1] => Array ( [key] => is_air_points_card [value] => yes [compare] => LIKE ) [2] => Array ( [key] => is_frequent_flyer_card [value] => yes [compare] => LIKE ) ) [3] => Array ( [key] => card_brand [value] => Array ( [0] => amex [1] => mastercard [2] => visa ) [compare] => IN [type] => CHAR ) [4] => Array ( [key] => card_provider [value] => Array ( [0] => anz [1] => asb [2] => bnz [3] => westpac [4] => kiwibank [5] => tsb [6] => warehouse_money ) [compare] => IN [type] => CHAR ) ) ) 

Code 2:

 Array ( [post_type] => page [posts_per_page] => 10000 [category_name] => active-cards [meta_query] => Array ( [relation] => AND [0] => Array ( [key] => card_purchase_rate [value] => Array ( [0] => 0 [1] => 46 ) [compare] => BETWEEN [type] => NUMERIC ) [1] => Array ( [key] => card_balance_transfer_rate [value] => Array ( [0] => 0 [1] => 14 ) [compare] => BETWEEN [type] => NUMERIC ) [2] => Array ( [relation] => AND [0] => Array ( [key] => is_rewards_card [value] => yes [compare] => LIKE ) [1] => Array ( [key] => is_air_points_card [value] => yes [compare] => LIKE ) [2] => Array ( [key] => is_frequent_flyer_card [value] => yes [compare] => LIKE ) ) [3] => Array ( [key] => card_brand [value] => Array ( [0] => amex [1] => mastercard [2] => visa ) [compare] => IN [type] => CHAR ) ) ) 

Code 3 (Dies ist ein Beispiel für den Post, der von Code 2 zurückgegeben wird. Code 1 sollte auch diesem Artikel entsprechen, aber nichts zurückgeben.

 Array ( [0] => WP_Post Object ( [ID] => 3742 [post_author] => 1 [post_date] => 2017-01-17 20:01:36 [post_date_gmt] => 2017-01-17 09:01:36 [post_title] => Westpac Airpoints Business MasterCard Credit Card [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => westpac-airpoints-business-mastercard-credit-card [to_ping] => [pinged] => [post_modified] => 2017-04-11 22:08:20 [post_modified_gmt] => 2017-04-11 11:08:20 [post_content_filtered] => [post_parent] => 0 [guid] => http://www.creditcardscompare.co.nz/?page_id=3742 [menu_order] => 0 [post_type] => page [post_mime_type] => [comment_count] => 0 [filter] => raw [meta] => Array ( [card_annual_fee] => Array ( [0] => 145 ) [card_purchase_rate] => Array ( [0] => 20.95 ) [card_balance_transfer_rate] => Array ( [0] => 1.99 ) [card_cash_rate] => Array ( [0] => 22.95 ) [card_interest_free_days] => Array ( [0] => 44 ) [card_provider] => Array ( [0] => Westpac ) [card_brand] => Array ( [0] => Mastercard ) [is_rewards_card] => Array ( [0] => a:1:{i:0;s:3:"yes";} ) [is_low_interest_card] => Array ( [0] => ) [is_no_annual_fee_card] => Array ( [0] => ) [is_balance_transfer_card] => Array ( [0] => ) [is_student_card] => Array ( [0] => ) [is_prestige_card] => Array ( [0] => ) [is_air_new_zealand_card] => Array ( [0] => ) [is_air_points_card] => Array ( [0] => a:1:{i:0;s:3:"yes";} ) [is_frequent_flyer_card] => Array ( [0] => a:1:{i:0;s:3:"yes";} ) [is_airpoint_lounge_access_card] => Array ( [0] => ) [is_best_card] => Array ( [0] => ) [is_black_card] => Array ( [0] => ) [is_business_card] => Array ( [0] => a:1:{i:0;s:3:"yes";} ) [is_cash_advance_card] => Array ( [0] => ) [is_cash_back_card] => Array ( [0] => ) [is_cheap_card] => Array ( [0] => ) [is_debit_card] => Array ( [0] => ) [is_flybuys_card] => Array ( [0] => ) [is_gold_card] => Array ( [0] => ) [is_high_income_card] => Array ( [0] => ) [is_home_loan_card] => Array ( [0] => ) [is_instant_approval_card] => Array ( [0] => ) [is_long_term_balance_transfer_card] => Array ( [0] => ) [is_low_annual_fee_card] => Array ( [0] => ) [is_low_income_card] => Array ( [0] => ) [is_no_foreign_transaction_fee_card] => Array ( [0] => ) [is_platinum_card?] => Array ( [0] => ) [is_purchase_protection_card] => Array ( [0] => ) [is_qantas_card] => Array ( [0] => ) [is_signup_bonus_card] => Array ( [0] => ) [is_travel_insurance_card] => Array ( [0] => ) [is_zero_balance_transfer_card] => Array ( [0] => ) [is_zero_interest_card] => Array ( [0] => ) [card_star_rating] => Array ( [0] => 4 ) ) [post_url] => http://www.creditcardscompare.co.nz/westpac-airpoints-business-mastercard-credit-card/ ) 

Zuletzt unten ist das eigentliche SQL, das von WordPress erzeugt wird, wenn ich das mit WP_Query ausführe:

 SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id ) INNER JOIN wp_postmeta AS mt2 ON ( wp_posts.ID = mt2.post_id ) INNER JOIN wp_postmeta AS mt3 ON ( wp_posts.ID = mt3.post_id ) INNER JOIN wp_postmeta AS mt4 ON ( wp_posts.ID = mt4.post_id ) INNER JOIN wp_postmeta AS mt5 ON ( wp_posts.ID = mt5.post_id ) INNER JOIN wp_postmeta AS mt6 ON ( wp_posts.ID = mt6.post_id ) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (78) ) AND ( ( wp_postmeta.meta_key = 'card_purchase_rate' AND CAST(wp_postmeta.meta_value AS SIGNED) BETWEEN '0' AND '30' ) AND ( mt1.meta_key = 'card_balance_transfer_rate' AND CAST(mt1.meta_value AS SIGNED) BETWEEN '0' AND '13' ) AND ( ( mt2.meta_key = 'is_rewards_card' AND mt2.meta_value LIKE '%yes%' ) AND ( mt3.meta_key = 'is_air_points_card' AND mt3.meta_value LIKE '%yes%' ) AND ( mt4.meta_key = 'is_frequent_flyer_card' AND mt4.meta_value LIKE '%yes%' ) ) AND ( mt5.meta_key = 'card_brand' AND mt5.meta_value IN ('amex','mastercard','visa') ) AND ( mt6.meta_key = 'card_provider' AND mt6.meta_value IN ('anz','asb','bnz','westpac','kiwibank','tsb','warehouse_money') ) ) AND wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10000 

Solutions Collecting From Web of "get_posts () und WP_query begrenzen “AND” -Bedingungen auf maximal 6 für Metawertabfragen in WordPress"