Problem with Updating Comment Meta
-
I have a scenario where I need to retrieve a custom field (‘current_module’) from a comment author’s user profile and add it to a custom field (‘author_current_module’) associated with any comment they submit. When I include the following code in my theme’s functions.php, nothing is saved to the comment’s custom field (I’ve verified by writing out the variables up until $comment_author_module_id to my log, and everything is working properly).
I’ve set up the custom fields (for both users and comments) using PODs plugin. I suspect that something is happening within PODS to intervene in the add_comment_meta function. Strangely, when I return the output of the function to my log file, I’m getting the ID of the comment instead of the ID of the custom field.
add_filter ('comment_post', 'comment_add_module', 10, 1); function comment_add_module($comment_id){ $comment_data = get_comment($comment_id); $comment_author_id = $comment_data->user_id; $comment_author_module = get_user_meta($comment_author_id, 'current_module', true); $comment_author_module_id = $comment_author_module['term_taxonomy_id']; add_comment_meta($comment_id, 'author_current_module', $comment_author_module_id, true); }
- The topic ‘Problem with Updating Comment Meta’ is closed to new replies.