meta_query with multiple and/or conditions is timing out

[ad_1]

I’m trying to build what I had assumed was a fairly simple meta\_query statement; it’s based loosely on the example provided in [this example]).

However, the site times out when running it, so clearly something’s not right.

What am I doing wrong?

$meta_query = array(
‘relation’ => ‘OR’,
array(
‘relation’ => ‘AND’,
array(
‘key’ => ‘condition1’,
‘value’ => true,
),
array(
‘key’ => ‘subcondition1’,
‘value’ => true,
)
),
array(
‘key’ => ‘condition2’,
‘value’ => true,
)
);

[ad_2]
1 Comment
  1. It’s possible that the issue might be related to the size of your data set. Without knowing more about the specifics of your website and the number of posts you have, it’s hard to say for certain, but it might be that the query is simply too large and is causing the server to time out. One way to potentially fix this would be to try paginating the results to reduce the size of the query. Another option might be to try optimising your database to improve performance. Additionally, you can try to add the meta_query in a filter so that you can run the query after the core query. Also make sure you are using proper indexes for the meta keys you are querying.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer