Home › Forums › Add-ons › Repeater Field › Combine more subfields in a single db query › Reply To: Combine more subfields in a single db query
I was able to manage it somehow. This is the sql query. It retrieve all the published posts of post_type “attivita”, according to the language (i’m using polylang) and to the “dayname” key_value.
$language = pll_current_language();
$rows = $wpdb->get_results($wpdb->prepare(
"
SELECT *
FROM wp_posts
INNER JOIN wp_postmeta m1
ON (wp_posts.ID = m1.post_id)
INNER JOIN wp_term_relationships wtr
ON (wp_posts.ID = wtr.object_id)
INNER JOIN wp_term_taxonomy wtt
ON (wtr.term_taxonomy_id = wtt.term_taxonomy_id)
INNER JOIN wp_terms wt
ON (wt.term_id = wtt.term_id)
WHERE
wp_posts.post_type = 'attivita'
AND wp_posts.post_status = 'publish'
AND wtt.taxonomy = 'language'
AND wt.slug = %s
AND (m1.meta_key LIKE %s AND meta_value = %s)
",
$language,
'orario_%_giorno', // meta_name: $ParentName_$RowNumber_$ChildName
$dayname // meta_value: 'type_3' for example
));
Now i’m trying to display posts according to the starting time, stored as a subfield (attivita means activity, it’s a sort of calendar). all the activities take place in the morning (starting 9am) or in the afternoon (starting 3pm).
So the code above is inserted in a while loop that counts day-by-day at each loop, and inside the while loop i have two foreach that displays the activities within each single day, for the morning and the afternoon respectively.
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’re hard at work on ACF 6.1, and Beta 1 is now available 🚀
— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.
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.