I have custom post types such as course
, lesson
, and lesson_topic
and I have ajax call to mark a lesson_topic
as favorite for a user. I am currently doing this in the ajax handler:
function topic_mark_favorite () {
if ( !wp_verify_nonce( $_REQUEST['nonce'], "topic_mark_favorite_nonce")) {
file_put_contents(ABSPATH.'wp-content/debug.log', 'Something went wrong' . PHP_EOL, FILE_APPEND);
exit("Something went wrong...");
}
$id = $_REQUEST["post_id"];
$user_id = get_current_user_id();
$result=0;
if ($user_id) {
$result = update_post_meta($id, 'user_favorite', $user_id);
}
if ($result) {
$result_type= 'success';
$result = ['type' => $result_type];
} else {
$result = ['type' => 'error'];
}
...
}
Wondering if this is sensible or if I should be doing this in fundamentally different way.
I thought about using user meta
and having meta field such as favorites
but then I would have to store JSON data there in order to extract what I need given a context.
For instance, depending on view I might want to get user favorites for a given lesson. Or for the entire course. Because I have existing post meta relationships I can always get lesson_topics for current lesson or for all lessons in a course. So that is why I thought about continuing using post meta but can't help but think maybe I am approaching this wrong.
Above said, I am thinking about just doing away with post meta and using custom tables...
Curious to hear thoughts!
Brian
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745041066a4607809.html
评论列表(0条)