Support

Account

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).'")';