Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring PHP Arrays in Wordpress User Meta Database
    primarykey
    data
    text
    <p>This should be easy for a PHP expert. I am having trouble storing and pulling arrays in Wordpress through the update_user_meta function.</p> <p>So I have an associative array built like so:</p> <pre>Array ( [film_genres] => Array ( [action] => 50 [comedy] => 50 [crime] => 50 [documentary] => 50 [drama] => 50 [family] => 50 [horror] => 50 [romantic] => 50 [sci-fi] => 50 [thriller] => 50 ) [film_types] => Array ( [blockbuster] => 0 [independent] => 0 ) [film_eras] => Array ( [1920s_1940s] => 0 [1950s_1960s] => 0 [1970s_1980s] => 0 [1990s_2000s] => 0 [post_2010] => 0 [pre_1920s] => 0 ) [last_updated] => 2011-10-12 21:21:28 )</pre> <p>But when I go to update this data in the user meta table via:</p> <p><strong>update_user_meta( $user_id, $meta_key, $meta_value, $prev_value )</strong></p> <p>The data gets put in the db properly, but when i call the data back and print the new array to screen, it has a nested array key of [0] within the array, like this:</p> <pre> Array ( [0] => Array ( [film_genres] => Array ( [action] => 50 [comedy] => 50 [crime] => 50 [documentary] => 50 [drama] => 50 [family] => 50 [horror] => 50 [romantic] => 50 [sci-fi] => 50 [thriller] => 50 ) [film_types] => Array ( [blockbuster] => 0 [independent] => 0 ) [film_eras] => Array ( [1920s_1940s] => 0 [1950s_1960s] => 0 [1970s_1980s] => 0 [1990s_2000s] => 0 [post_2010] => 0 [pre_1920s] => 0 ) [last_updated] => 2011-10-12 21:21:28 ) ) </pre> <p>How can I get it to store the array exactly like my first array? I am pulling the meta value array via the WP command: </p> <p><code>$wp_user_film_prefs_arr = get_user_meta( $wp_user_id, $wp_user_film_prefs_key_label, false );</code></p> <p>Is there something I'm doing wrong? Thanks in advance!!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload