• I am trying to use wp_dropdown_users in order to save a users name to an inventory item. Currently I am using WP Inventory Manager. I am trying to have it set where you can choose a user from the wp_dropdown_users drop-down and save it for that entry.

    /**
    * @param $item
    */
    function my_custom_function( $item ) {
    wp_dropdown_users( array(‘show_option_none’ => __(‘No user selected’) ) );

    }

    add_action( ‘wpim_admin_pre_edit_item’, ‘my_custom_function’ );

    This code is generating my User list drop-down on the inventory pages.

    I don’t have a lot of experience with mySQL, but I’m assuming I need to save it to a database using POST somehow? I’m not much of a back-end coder so I’m just kind of lost at how to tackle this.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WP Inventory

    (@chuck1982)

    Hey Rob,

    Happy to point you in the right direction. Yes, to actually edit the item from the frontend, you’ll need to make that dropdown part of a form that when it submits, updates the inventory item. That form will also need a (hidden) input with the inventory item ID so you can update the right one. The table you’ll be looking for is {prefix}_inventory_item.

    Thread Starter rob1021

    (@rob1021)

    Is there any way to use these: https://www.wpinventory.com/documentation/developer-documentation/actions/item-management/wpim_admin_edit_after_field/

    Trying to add a user drop down field but don’t know how to save the selection in the entry.

    I want to be able to display a user list in each items admin pages. The problem I’m having is the actions don’t save the selection (even if it’s just text). Is there an easy way to add a field AND save the data in the entry?

    Looking into the paid version for my company, but I need to add this in for a proof of concept first.

    Plugin Author WP Inventory

    (@chuck1982)

    Hi Rob,

    I believe you’ll need to add a name to your input field through the parameters of the user dropdown function, as that’s how the form field is categorized when saving settings. https://developer.www.ads-software.com/reference/functions/wp_dropdown_users/

    Let me know if that doesn’t work.

    Best,
    WP Inventory

    Thread Starter rob1021

    (@rob1021)

    Not sure if explaining correctly. I want something like this:

    function my_custom_function( $item, $inventory_id ) {
    //some code to do user drop down and get that in a variable.
    Echo variable;
    }

    add_action( ‘wpim_admin_edit_form_after_media’, ‘my_custom_function’, 10, 2 );

    Now how would I save the selection? I can add a field to the edit page, but it does not save the data once you leave the page.

    Plugin Author WP Inventory

    (@chuck1982)

    Hi Rob,

    The hook adds your field to the form, so it’s part of the data being saved, it’s just a matter of making sure the system recognizes it. Part of that is making sure the input has a “name” attribute, and that’s the name associated with that value when the form data is posted.

    You can specify the name just by adding it as an attribute in your wp_dropdown_users settings array.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Saving wp_dropdown_users choice on the page’ is closed to new replies.