Home › Forums › Add-ons › Repeater Field › SQL Query for all ACF Data for a post › Reply To: SQL Query for all ACF Data for a post
There is not a single query that you can run to get all fields specifically related to ACF. The best that you can to is to get all the post_meta values, something like
'SELECT * FROM wp_postmeta WHERE post_id = "'.$post_id.'"';
You could do a query to get all the ACF fields related to a post, basically looking for a meta_value that starts with ‘field_’
'SELECT * FROM wp_postmeta WHERE post_id = "'.$post_id.'" AND meta_value LIKE "field\_%"'
Then you could loop through the results and get the real meta_key value
$fields = array();
foreach ($results as $result) {
$fields = substr($result['meta_key'], 1);
}
$query = 'SELECT * FROM wp_postmeta WHERE post_id = "'.$post_id.'" AND meta_key IN ("'.implode('","', $fields).'")';
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.