Skip Navigation

[Resolved] Pre-selection of taxonomy items in the post form for registration

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by chelhwanS 1 year, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2544811

Tell us what you are trying to do?

When creating an input post form, having a module that pre-specifies and stores certain categories of items has several uses.

An example of code is taxonomy, the slug "youtube-video".
And there are several items in the above taxonomy.
Also, you need a code that is saved together when saving by selecting one of these in advance in the input form.

You can use the slug "general-health-video" as an example of an item.
In this case, it would be better to not show the pre-selection to the user.

I've read some explanations, but I don't understand it well, so I'd like you to make a code.

*****
Is there any documentation that you are following?
https://toolset.com/forums/topic/preselcting-categories-based-of-custom-field-selection/
I can't understand even if I read it.

What is the link to your site?
I'm working on several sites, most of them have a need.

#2544869

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand - you have created a post form to create new post and with whatever new posts are created using this Toolset post form you want to attach a taxonomy term to that newly created posts. Is that correct? If yes:

Can you please share screenshot of what post form you created and what taxonomy term you want to assign automatically when user create new posts.

#2546915
2023-02-23-1.png

The current screen is a multi select, but if only one of the items is selected in advance, the multi select screen will not be visible.
Currently, it is a method that notifies the user of the category to be selected by a message in advance.

#2546997

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Do you mean that when you display the taxonomy field with your form it does not display the checkboxes?

Can you please share problem URL and admin access details and detail steps that should help me to see the issue.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2551473

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've removed the product category taxonomy field from your form.

Then, I've added the following hook to "Custom Code" section offered by Toolset:
=> hidden link

add_action('cred_save_data', 'func_set_default_terms',10,2);
function func_set_default_terms($post_id, $form_data) {
  $forms = array( 160564 );
  if ( in_array( $form_data['id'], $forms ) ) {
     
    wp_set_object_terms($post_id,'health-food', 'product_cat');
  }
}

More info:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#2551483

Thank you.

I would like to ask you one more thing.

Custom code can only be used in certain cases.

" wp_set_object_terms($post_id,'health-food', 'product_cat');"

If something like 'health-food' or 'product_cat' is specified in the form, it can be used for various purposes.

Could you please rework the code?

#2551513

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sorry - you do not want to display the product_cat field with the form and you just want to preselect the term in product_cat field and hide it - so the code I shared is doing the same thing.

Can you please explain me what exactly you want to do?

#2554883

I'll make it.
Thank you for your effort

My issue is resolved now. Thank you!