admin管理员组

文章数量:1201373

hey guys i'm trying to import my plugin option into wordpress with php but i can't find any tutorial or describe about this section

i have this example:

my option name:

get_option('meow');

what i have in this option are

'cats'=> '2',
'food' => array('tona','fish'),

so how can i use

update_option

to import this values? i tried this way but it's not working

update_option('meow', 'cats','5');

hey guys i'm trying to import my plugin option into wordpress with php but i can't find any tutorial or describe about this section

i have this example:

my option name:

get_option('meow');

what i have in this option are

'cats'=> '2',
'food' => array('tona','fish'),

so how can i use

update_option

to import this values? i tried this way but it's not working

update_option('meow', 'cats','5');
Share Improve this question edited Jun 14, 2022 at 8:30 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jun 14, 2022 at 3:54 Ahmed javaAhmed java 153 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Just pass the array as the second argument to update_option - WordPress will serialize the value before storing it in the database, and automatically unserialize it when you read it:

update_option( 'meow', array(
    'cats' => '2',
    'food' => array( 'tona', 'fish' ),
) );

$meow = get_option( 'meow' );

print_r( $meow );

// Array
// (
//     [cats] => 2
//     [food] => Array
//         (
//             [0] => tona
//             [1] => fish
//         )
// )

本文标签: How Can i import plugin option