Home › Forums › Add-ons › Repeater Field › Mistake in documentation ? : Query posts by custom fields › Reply To: Mistake in documentation ? : Query posts by custom fields
If the query does not differentiate between fields in different rows, i don’t understand why there is a repeater field. One field stat_date and one field end_field are enough ^^’.
Finally, WP_Query is too slow : 17 seconds with 2 rows and timeout with 3 rows and i don’t know why, the request does not seem so complicated :
Array
(
[post_type] => distributeur
[posts_per_page] => 1
[meta_query] => Array
(
[relation] => AND
[0] => Array
(
[key] => code pays
[value] => fr
)
[1] => Array
(
[relation] => OR
[0] => Array
(
[relation] => AND
[0] => Array
(
[key] => rc_cp_min_0
[value] => 7000
[type] => numeric
[compare] => <=
)
[1] => Array
(
[key] => rc_cp_max_0
[value] => 7000
[type] => numeric
[compare] => >=
)
)
[1] => Array
(
[relation] => AND
[0] => Array
(
[key] => rc_cp_min_1
[value] => 7000
[type] => numeric
[compare] => <=
)
[1] => Array
(
[key] => rc_cp_max_1
[value] => 7000
[type] => numeric
[compare] => >=
)
)
[2] => Array
(
[relation] => AND
[0] => Array
(
[key] => rc_cp_min_2
[value] => 7000
[type] => numeric
[compare] => <=
)
[1] => Array
(
[key] => rc_cp_max_2
[value] => 7000
[type] => numeric
[compare] => >=
)
)
)
)
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[comments_popup] =>
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[fields] =>
[menu_order] =>
[...]
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[update_post_meta_cache] => 1
[nopaging] =>
[comments_per_page] => 50
[no_found_rows] =>
[order] => DESC
)
SQL :
SELECT SQL_CALC_FOUND_ROWS
wp_posts.ID
FROM
wp_posts
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_postmeta.meta_key = 'code pays'
AND CAST(wp_postmeta.meta_value AS CHAR) = 'fr')
AND (((mt1.meta_key = 'rc_cp_min_0'
AND CAST(mt1.meta_value AS SIGNED) <= '7000')
AND (mt2.meta_key = 'rc_cp_max_0'
AND CAST(mt2.meta_value AS SIGNED) >= '7000'))
OR ((mt3.meta_key = 'rc_cp_min_1'
AND CAST(mt3.meta_value AS SIGNED) <= '7000')
AND (mt4.meta_key = 'rc_cp_max_1'
AND CAST(mt4.meta_value AS SIGNED) >= '7000'))
OR ((mt5.meta_key = 'rc_cp_min_2'
AND CAST(mt5.meta_value AS SIGNED) <= '7000')
AND (mt6.meta_key = 'rc_cp_max_2'
AND CAST(mt6.meta_value AS SIGNED) >= '7000'))))
AND wp_posts.post_type = 'distributeur'
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'acf-disabled'
OR wp_posts.post_status = 'future'
OR wp_posts.post_status = 'draft'
OR wp_posts.post_status = 'pending')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0 , 1
Yes it’s a little more complicated than ACF example and they are postal codes and not dates but principle is the same.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.