Skip Navigation

[Resolved] Setting a value in CRED form Select field based on User record data

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)


I have a CRED form for entering 'inventory' items. When new Users are created, they are assigned to a particular 'Department'. When a User is adding a new inventory item using the CRED form, I want that User's department to be added to the new item's record and displayed without the User being able to change it. Can this be done using a manually edited Conditional Group on the inventory CRED form?



Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)


Thank you for contacting us and I'd be happy to assist.

To achieve this, you can add one select type field user field 'Users Department' and another select type custom field 'Inventory Department' for the inventory record post type.

Both these fields will have the same options with the same values.

When a new user will be created, a department will be selected for his/her 'Users Department' field.

And in the form to create a new inventory post, you can use the Types fields API shortcode in the 'Inventory Department' field's default value:
( ref: )

[types usermeta='users-department' output='raw' current_user='true'][/types]

As a result, when the inventory form will load, the department of the current user will automatically be selected. And you can use the custom CSS code to hide this field from the users so that they can't change its value from the form.

I hope this helps and please let me know if you need further assistance.



Thank you for your assistance, Waqar. How would I change this if 'Department' is a taxonomy of the inventory CPT? (This is to simplify the display of inventory items for particular departments with category archives.)


is it possible for ‘Department’ in the inventory post to be a taxonomy instead of a select field?



Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

For attaching the department as the taxonomy term, you'll need to add the following changes:

1. In the user field 'Users Department', you'll need to make sure that the individual option values are the same as the 'slugs' of each of the 'Department' taxonomy terms.

2. In the form that adds the 'Inventory' post, you'll add a 'hidden' type generic field with the slug 'department-slug'. In the field's default value, you'll use the same shortcode that gets the value of the 'Department' taxonomy slug from the user field:

[types usermeta='users-department' output='raw' current_user='true'][/types]

3. The last step would be to use a custom function attached to the 'cred_save_data' hook, that gets the slug of the term from the generic field, and attaches it as the taxonomy term of the created 'Inventory' post, when the form submission completes:
( ref: )

add_action('cred_save_data', 'custom_add_department_term',10,2);
function custom_add_department_term($post_id, $form_data)
    // if a specific form
    if ($form_data['id']==12345)
        // target taxonomy slug
        $taxonomy = 'department-tax';

        // term slug value from the generic field
        $term_slug = $_POST['department-slug'];

        // set the term with the created post
        wp_set_post_terms( $post_id, $term_slug, $taxonomy, false );       

Note: You'll replace '12345' and 'department-tax', with the actual form ID and the 'Department' taxonomy's slug, used on your website, respectively/

The above code snippet can be included through either Toolset's custom code feature ( ref: ) or through the active theme's "functions.php" file.


Sorry for the delay in replying - I have only been able to get back to this topic today. I have been trying the last set of suggestions not having success yet as I'm not sure about the various slugs...


I was able to achieve the functionality needed with Waqar's excellent support.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.