$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wpdb - How to work with constraints on wordpress user metadata?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wpdb - How to work with constraints on wordpress user metadata?

matteradmin8PV0评论

For example, I want to add a custom user metadata field for projects he is assigned to. But this field must have a foreign key constraint to another table to make sure that the project it is referencing, is valid.

Is there a way to handle this scenario with pure user metadata instead of creating an extra table to link the users with the projects?

For example, I want to add a custom user metadata field for projects he is assigned to. But this field must have a foreign key constraint to another table to make sure that the project it is referencing, is valid.

Is there a way to handle this scenario with pure user metadata instead of creating an extra table to link the users with the projects?

Share Improve this question asked Mar 6, 2019 at 14:01 HimadHimad 5552 silver badges9 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

You won’t be able to do this with meta. All user meta is stored in the meta_value column of wp_usermeta, so if you tried to set a constraint on that column you’d just prevent any other user meta from being set.

You should be able to store the project id(s) as a string in the wp_usermeta table, but a constraint won't work since the meta_value column is used for many different things. Instead, database INSERT and UPDATE triggers could probably be used, though writing correct ones would take more work and thought than just quickly defining a foreign key constraint would.

Post a comment

comment list (0)

  1. No comments so far