Skip Navigation

[Resolved] Update user meta

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

Problem:

How to pass post term value to user field using custom codes.

Solution:

I suggest you try these:

https://toolset.com/forums/topic/update-user-meta-2/#post-1279233

Relevant Documentation:

https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field

This support ticket is created 5 years, 7 months 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
- 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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by souhirB 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1279185
toolset.jpg

Hi
I closed my ticket by mistake
https://toolset.com/forums/topic/update-user-meta/#post-1269747

"Alternatively, you should be able to get the term slug also with PHP code, if you first declare the global $WP_Views in your code:

global $WP_Views;
$term = $WP_Views->get_current_taxonomy_term();

when i use
global $WP_Views; in my function with cred_save_data

$term = $WP_Views->get_current_taxonomy_term();

It add a blank (see image)

( I tried to test with shortcode i get "Catchable fatal error: Object of class WP_Term could not be converted to string in" )

hank you

#1279233

Hello,

When you submit the form, trigger your custom PHP function with action hook cred_save_data, there isn't terms loop, so the custom PHP codes won't work.

I suggest you try these:
1) in the view's loop( view displaying a list of categories), you can get the term's slug with Views shortcode:
[wpv-taxonomy-slug]

2) Use above value to setup a generic hidden field inside your form content(2 forms follow/unfollow), for example:

[cred_generic_field field="term-slug" type="hidden" class=""]
 {
  "required":0,
  "default":"[wpv-taxonomy-slug]"
 }
[/cred_generic_field]

Above generic hidden field will be able to pass POST parameter "term-slug", value is term's slug

3) In your custom PHP codes, you can get the value of POST parameter "term-slug", like this:

$term = $_POST['term-slug'];

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-taxonomy-slug
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field

#1280525

My issue is resolved now. Thank you!