plugins – Save custom wordpress field to metadata

Question

I have created select fields via a hook in the edit view for posts that get their options from an api.

Currently I am not able to save the data from the select field into the metadata when updateing the post.

I am trying to save the data using the save_post() function.
I access the field i want to save via the name attribute


echo('<select name="level" id="level">');
    foreach($seniorityLevels as $seniorityLevel){
    echo('<option value="'.$seniorityLevel->id.'">'.$seniorityLevel->name.'</option>');
    }
echo('</select>');

add_action('save_post', add_post_meta_for_hooks);
function add_post_meta_for_hooks() {
   $post_id = get_the_ID();
   add_post_meta($post_id, 'join_level' , $_POST->level);     
}

This does not seem to be the right way to access the select value.
May you can help me. Thank you in advance.

0
gncx 3 weeks 2023-05-12T11:05:38-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse