我有一个自定义插件,它会为每个用户生成一些数据。
我要用数据库带来并发送到的数据替换用于测试的硬编码数据,并希望得到一些建议。
每个用户的数据如下:
我的问题是-是将其存储为meta_key数组还是单独字段的最有效方法?
再次,这将是每个用户对每一个帖子,所以我担心膨胀不必要的分贝。
我也不明白如何将所有的子变量分配给postID的父变量。
我认为我这样做是正确的,但不明白为什么会有“你的钥匙”:
$the_meta_array = array (
'postID' => ‘$post->ID’,
array (
'currentScore' => 'value-2',
'totalScore' => 'value-3',
'totalSpend' => 'value-4',
'timesWon' => 'value-5',
'wonTotal' => 'value-6',
));
$user_id = wp_get_current_user();
$user_meta_key = 'your-key';
add_user_meta( $user_id, $user_meta_key, $the_meta_array );谢谢。
发布于 2019-07-01 15:45:26
这段代码将保存每个使用postID作为meta_key的数组,如下所示:用户1301 currentScore totalScore . 1302 currentScore totalScore .
$the_meta_array = array (
'currentScore' => 'value-2',
'totalScore' => 'value-3',
'totalSpend' => 'value-4',
'timesWon' => 'value-5',
'wonTotal' => 'value-6',
);
$user_id = wp_get_current_user();
$user_meta_key = 'userScore' . $post->ID;
add_user_meta( $user_id, $user_meta_key, $the_meta_array );正如O.Jones所建议的那样,为meta_key使用一个不同的前缀(例如'userScore-')
https://stackoverflow.com/questions/56836903
复制相似问题