Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Saving value from wp_dropdown_users as meta?

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #42150
    notfilc
    Member

    I’m familiar with adding custom meta boxes to my post types in WordPress but this is something I’ve not had to do before. I want to be able to select a user from a dropdown (in a metabox) and have that value saved with the post.

    Here’s my code:

    function add_users_meta_box() {
    add_meta_box(
    ‘users_meta_box’, // $id
    ‘Assign to user’, // $title
    ‘show_users_meta_box’, // $callback
    ‘property’, // $page
    ‘side’, // $context
    ‘high’); // $priority
    }

    add_action(‘add_meta_boxes’, ‘add_users_meta_box’);

    function show_users_meta_box() {
    wp_dropdown_users(array(‘name’ => ‘author’, ‘show_option_none’ => ‘– None –‘,’selected’ => $user_id));
    }
    Is it possible to extend this to both save the value and when the user re-opens the post to edit, have the position of the dropdown saved.

    If anyone could point me in the right direction it would be much appreciated.

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.