0

I have built a custom post type of "grades." Within that I am using the Advanced Custom Fields repeater field named "assignment". Within the repeater "assignment" field are these three repeating sub-fields, "assignment_name", "date_of_completion", and "grade".

I have installed a report plugin that accepts a MySQL database query. My problem is that I can't get the query to pull in any of the meta that is being added via ACF. I looked into the database using phpmyadmin, and it looks like the metakey is different based on how many repeating fields are added to the post.

How can I modify this query for a meta_key that's constantly changing?

Here's my query so far, any help would be greatly appreciated.

SELECT p.post_id,
       pm.assignment_0_assignment_name, //An always changing metakey based on number of repeating entries
       pm.assignment_0_date_of_completion, //An always changing metakey based on number of repeating entries
       pm.assignment_0_assignment_grade//An always changing metakey based on number of repeating entries

FROM wp_posts p 
   INNER JOIN wp_postmeta pm 
       ON p.post_id = pm.post_id

WHERE p.post_type = 'grades'    
AND p.post_status = 'publish'
3
  • the "duplicate" that is referenced doesn't address the fact that my metakey can be different each time. Sometimes the post has assignment_0_assignment_name. assignment_1_assignment_name, assignment_2_assignment_name. I need to be able to write one query that accounts for that. If the "duplicate" answers my question, would you please elaborate?
    – TripsLeft
    Nov 1, 2014 at 20:24
  • Why aren't you using the acf (and wp) functions for this? Why do you want to do it with a MySQL query?
    – alpipego
    Nov 7, 2014 at 11:02
  • Because I'm using a reporting plugin that exports to a csv. The plugin gathers the report data using a MySql query. Otherwise, I would have preferred using the built in wp db querying functions
    – TripsLeft
    Nov 8, 2014 at 13:24

0