Support

Account

Home Forums Add-ons Repeater Field SQL Query for all ACF Data for a post

Solved

SQL Query for all ACF Data for a post

  • Can you help me with a query that i can run in SQL to get all the ACF related to the post is specify with where clause.

  • 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).'")';
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘SQL Query for all ACF Data for a post’ is closed to new replies.