Skip Navigation

[Resolved] Update taxonomy from within a Content Template

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to add a button to my Content Template that allows Users to modify the post's taxonomy terms.

Solution: You can create a Form that edits this post, and remove the input fields except for the taxonomy field. Hide the field with CSS or by making it a hidden field type, and show only the submit button. Use wp_set_object_terms to modify the post's terms.

Relevant Documentation:
https://codex.wordpress.org/Function_Reference/wp_get_object_terms

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 3 voices.

Last updated by Christian Cox 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1149658
Screen Shot 2018-11-19 at 8.38.16 PM.png

I have a Content Template that is showing the details of a CPT (Single View).

There is a Custom Taxonomy associated with this CPT. I want to to provide a button or a link for the user to click it and that would change the Taxonomy value to a new value.

Can I create a shortcode or something to be called when the button/link is clicked to change the Taxonomy value?

Attached image shows what I am trying to do.

#1149711

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - what if you create a Toolset form that holds the submit button and the taxonomy in a hidden format and when you submit the form - it should change/set the taxonomy as required.

If you can share problem URL where you added the button and send me access details I will try to play with it and guide you with a solution.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

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

#1149851

Minesh.. That's exactly what I had to do. I created separate forms for each function that i needed to perform.

I had to create custom code to update the taxonomy that I wanted.

    if ($form_data['id']==100) {
		wp_set_object_terms( $post_id, array ('hidden'), 'product-status'); 
    }

But I want see the current value of the taxonomy but having trouble reading it. Here's what I am trying to do..

    if ($form_data['id']==100) {
        if (wp_get_object_terms( $post_id,  'product-status') == 'published') {
		wp_set_object_terms( $post_id, array ('hidden'), 'product-status'); 
        }
    }

Having trouble getting with wp_get_object_terms to get the current value of the taxonomy. Can you please help with this last piece?

Thanks.

#1149863

Minesh
Supporter

Languages: English (English )

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

Well - as you can see with WordPress Doc for function "wp_get_object_terms"- the return value is array.
=> https://codex.wordpress.org/Function_Reference/wp_get_object_terms

Please check the example given with above link to see how you can iterate through the return array. If you do not know, please share problem URL and access details with all required information.

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

#1152758

User requested this ticket be resolved, see here: https://toolset.com/forums/topic/unable-to-close-out-issue