How to save data of an input field to an array

Don’t use update_usermeta, it is deprecated, update_user_meta is the one to use. You get the previously saved value out with get_user_meta. <input type=”text” name=”group[]” id=’group[]’ class=”regular-text” value=”<?php echo esc_attr( get_user_meta( $user->ID, ‘group’, true ) ); ?>” />

How pass a 0 in $atts?

This happens, because WP checks the value with empty(): if ( ! empty( $value ) ) … and empty() is TRUE for values like 0 or “0”. You have two options now: Filter walker_nav_menu_start_el and replace <a with <a tabindex=0. Pass $atts[‘tabindex’] = “0 “; in your original function. Note the extra space. It circumvents … Read more

Return array keys and values

This is not really a WordPress question but more PHP. To solve this problem, you need to use $value as your key as well plus _id You can do something like this $options[$value . ‘_id’] = ot_get_option($value); EDIT If you need $key to be the value of id, you can also try something like this … Read more

WordPress Plugin Dev: Using array for WP options

If you are using the Settings API then you don’t have to save the options, that’s done for you. So when using an array to store the options your validation function should get an array of all existing options, update only the changed and return that array. Something like this: function my_settings_option_validate( $input ) { … Read more

How to use IN array properly in WordPress?

You need to have your replacement placeholders matching the number of values in your array, and then you can use the array as one of the prepare arguments. Proof of concept: $a = array(‘course_3202′,’course_3201′,’course_3200′,’course_3199′); $b = array_fill(0,count($a),’%s’); $b = implode(‘,’,$b); $sql = “SELECT * FROM $wpdb->postmeta”; $sql .= ” WHERE meta_key IN ({$b}) and meta_value=1″; … Read more

Replace text inside a huge multidimensional array

Try this php built-in function array_walk_recursive function wpse_do_something_on_data() { $data = array( ‘repeater-1’ => array( array( ‘user_defined_field1’ => ‘http://www.domain-001.com’, ‘user_defined_field2’ => ‘http://www.domain-002.com’, ), array( ‘user_defined_field1’ => ‘http://www.domain-011.com’, ‘user_defined_field2’ => ‘http://www.domain-012.com’, ), ), ‘repeater-2’ => array( array( ‘user_defined_field1’ => ‘http://www.domain-101.com’, ‘user_defined_field2’ => ‘http://www.domain-102.com’, ), array( ‘user_defined_field1’ => ‘http://www.domain-111.com’, ‘user_defined_field2’ => ‘http://www.domain-112.com’, ), ), ); array_walk_recursive( $data, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)