admin管理员组文章数量:1326287
The plan is for users to be able to store locations and have notes and other variables for each location. These locations would later be shown on a map, so I would need to be able to quickly access the data also. I was just wondering what the best way to go about this would be before I try to get things set up with the map api so I don't have to go back and change everything later. Thanks.
The plan is for users to be able to store locations and have notes and other variables for each location. These locations would later be shown on a map, so I would need to be able to quickly access the data also. I was just wondering what the best way to go about this would be before I try to get things set up with the map api so I don't have to go back and change everything later. Thanks.
Share Improve this question asked Jun 18, 2015 at 4:00 MikeMike 113 bronze badges1 Answer
Reset to default 1You should store additional user data in wp_usermeta
table. For that, use add_user_meta() function. Here's an example of how you can store locations
$location = array('name' => 'example location name',
'street' => 'example street name',
'note' => 'example user note'
);
add_user_meta($user_id, 'location', $location);
You can store as many locations as you want. To retrieve the locations use get_user_meta() They will be returned as array of locations.
$locations = get_user_meta($user_id, 'location');
foreach($locations as $location) {
echo $location['name'];
}
To update a particular location, you can use update_user_meta(). But it's a little tricky as every location will have the same meta_key
named location
. So, you need to also send the previous meta_value
to let Wordpress know exactly which row you want to update. Here's a example to update a location with street name abcd street
foreach($locations as $location) {
if($location['street'] = 'abcd street') {
$new_location = array('name' => 'Modified location',
'street' => 'Modified street',
'note' => 'Modified Note'
);
update_user_meta($user_id, 'location', $new_location, $location);
}
}
本文标签: databasewhat is the best way to store user created data
版权声明:本文标题:database - what is the best way to store user created data? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742211327a2433765.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论