I have multiple custom post types registered.
I am using the “Advanced custom fields” plugin and using the “Relationship” field type.
My query at the moment looks like this, but it seems to be rather expensive so i am looking for a better way to write it. The more arrays I add to it the longer it takes to complete the query. The three that i have is not so bad, but another post type that i have has around 13. It takes over a minute to complete that query. That is just too long.
Take a look at this code:
$leaders = get_posts(array(
'post_type' => 'leadership',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'expertise_relationship', // name of custom field
'value' => '"40"', // exact match for Government
'compare' => 'LIKE'
),
array(
'key' => 'expertise_relationship', // name of custom field
'value' => '"39"', // exact match for Social Marketing & Advocacy
'compare' => 'LIKE'
),
array(
'key' => 'expertise_relationship', // name of custom field
'value' => '"38"', // exact match for Healthcare
'compare' => 'LIKE'
)
)
));
More or less what it is doing is looking in the custom post type “leadership” for any posts with a expertise relationship of goverment, social marketing, and healthcare.
Is there a way write this shorter or differently in order to optimize the query?