I have saved arrays in custom post fields and I am retrieving them directly from the db.
$ga_set = get_meta_values_from_all_posts('ganalytics_settings', 'post', 'draft');
function get_meta_values_from_all_posts( $key = '', $type = 'post', $status = 'publish' ) {
global $wpdb;
if( empty( $key ) )
return;
$r = $wpdb->get_col( $wpdb->prepare( "
SELECT pm.meta_value FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
WHERE pm.meta_key = '%s'
AND p.post_status = '%s'
AND p.post_type = '%s'
", $key, $status, $type ) );
return $r;
}
The result I am getting back looks like the following:
Now I would like to iterate through the array in a for loop:
for ($i = 0; $i < count($ga_set); $i++) {
$settings= $ga_set[i];
...
}
However, $settings
is null
.
Any suggestions how to get the value of $ga_set
to $settings
?
I appreciate your reply!
UPDATE
The string that is stored in $ga_set
is
"a:8:{s:11:\"use_own_api\";b:0;s:16:\"google_auth_code\";s:45:\"4/hLXqq9X7sX1sOY-K6MhpEZu6bc8fGGADKLnjlcWA-p4\";s:14:\"google_api_key\";s:39:\"AIzaSyAJjpxVYfZ0WQPZSPr72DOuKU3X-sXquqM\";s:16:\"google_client_id\";s:39:\"180054848980.apps.googleusercontent.com\";s:20:\"google_client_secret\";s:24:\"XtEhZR8lUdRnzx5zdH7KsUaY\";s:19:\"google_access_token\";s:215:\"{\"access_token\":\"ya29.Ci8YA6-Ar2eJC21YOxaZEAuWKWLLgTbq_R_-kjR9Acz4UBF92s0hQGCkSUJfh3BvuQ\",\"token_type\":\"Bearer\",\"expires_in\":3600,\"refresh_token\":\"1/zDGdHo4JTJ6o9TOoZyxnY6e89gUc2UJ6G4\",\"created\":1467867036}\";s:22:\"ga_active_web_property\";O:18:\"Google_Webproperty\":20:{s:9:\"accountId\";s:8:\"79991596\";s:18:\"\u0000*\u0000__childLinkType\";s:27:\"Google_WebpropertyChildLink\";s:22:\"\u0000*\u0000__childLinkDataType\";s:0:\"\";s:9:\"childLink\";O:27:\"Google_WebpropertyChildLink\":2:{s:4:\"href\";s:105:\"https://www.googleapis.com/analytics/v3/management/accounts/79991596/webproperties/UA-79991596-2/profiles\";s:4:\"type\";s:18:\"analytics#profiles\";}s:7:\"created\";s:24:\"2016-06-28T19:40:27.202Z\";s:2:\"id\";s:13:\"U"