Home › Forums › ACF PRO › Querying Relationship Fields with SQL › Reply To: Querying Relationship Fields with SQL
Edit. The above query should use a LEFT JOIN towards the end.
SELECT
wp_shzat400yd_data_questions.*,
wp_shzat400yd_posts.post_content,
wp_shzat400yd_posts.post_title,
wp_shzat400yd_postmeta.post_id AS section_id,
wp_shzat400yd_postmeta.meta_value,
wp_shzat400yd_postmeta.meta_key
FROM wp_shzat400yd_data_questions
INNER JOIN wp_shzat400yd_posts
ON wp_shzat400yd_data_questions.question_id = wp_shzat400yd_posts.ID
LEFT JOIN wp_shzat400yd_postmeta
ON wp_shzat400yd_posts.ID LIKE CONCAT('%', wp_shzat400yd_postmeta.meta_value, '%')
WHERE wp_shzat400yd_postmeta.meta_key = 'questions';
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.