Retrieving meta values from database

I am working on this database in which the data is serialized and its in multidimensional array. I am trying to retrieve the data into CSV file. One more thing to mention is being saved from WordPress. I read that WordPress automatically serialize the data and saves to database. What would be the best practice to retrieve the data and is it possible to chose the data which is saved in each array. This is the first time I am working with WordPress so any help would be great

Here is what I am doing right now:

$values = mysql_query("select userid,metavalue from wp_usermeta where meta_key='course_progress'");

while ($rowr = mysql_fetch_row($values)) {

        $sdata = array(); 
        $sdata = maybe_unserialize( $rowr[1] );

        $csv_output .= '"'.$rowr[0].'"';

        foreach ( (array) $sdata as $value) {

                $csv_output .= ',"'.implode("::",$value).'"';
            }

        $csv_output .= "n";
    }

Related posts

1 comment

  1. If you are trying to get user information or meta value from usermeta table in
    wordpress

    you must use get_user_meta() function.

    for e.g suppose you want to get first_name of user’s then you have to
    write

    get_user_meta(user_id,’first_name’,true);

Comments are closed.