Skip Navigation

[Resolved] Update user meta

This support ticket is created 5 years, 8 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Author
Posts
#1268717
folow.png
followtaxonomy.png

Tell us what you are trying to do?
I created 2 forms follow/unfollow which update user meta on save (update / delete) the taxonomy from user prefered field it work fine. (first image follow.png)
I want to use this form in view displaying a list of categories (second image followtaxonomy.png)

Is there a similar example that we can see?
(second image)

thank you

#1269025

You mean, you need an example about how to create the layout of followtaxonomy.png, where you could press the "+" to subscribe and eventually unsubscribe as well?

To do this, you'd have to alter everything that is "interactive", hence the Form, in the Form Editor.
So you would add a "+" Icon in the Submit Button instead of the classic "Submit" Text, and you'd style that Form so to output exactly only the button you want (subscribe, unsubscribe).
Eventual fields you need in this form should be hidden with CSS, I assume your form already works fine and can take dynamic input from a View (which is basically the results of a Query).

Hence you'd edit the View loop, for example with the Loop wizard. You can choose a Bootstrap Grid for example, and then output at first some dummy data like the Post Title, using the Loop Wizard.
This will print all needed HTML to the View Loop and you can then head to the Loop Item Content Template, remove the dummy data you added and instead insert the Toolset User Form you created.
Note, this Form will ask you what user to edit, and logically you cannot choose "the user in the loop" as this is not a User View.
But it will default to editing the current user, which is the one logged in.

Now you already have a pretty nice looking grid of Forms on the Front End if you insert this View somewhere.
Now you could add Images in the Loop just above the Form in the Loop Item, images that probably are saved as a Custom Term Field.
With this, you'd have the layout you need.

I think this DOC will help further as well:
https://toolset.com/documentation/user-guides/view-layouts-101/

#1269637

Hi Beda thank you for your response (excuse my english)
My follow/unfollow button works fine in a single taxonomy page, i use this function to update user meta

 add_action('cred_save_data', 'func_update_candidate_url',10,3);
function func_update_candidate_url($user_id, $form_data){
    global $current_user;
    if ($form_data['id']==5427){
         $cat = get_category( get_query_var( 'cat' ) );
$term = get_queried_object();
		$cat_slug = $cat->slug;  {
		add_user_meta ($user_id, 'wpcf-subscriptionnewm', $cat_slug);
             

My problem is : how to get the slug of the taxonomy in the loop (page where i have a list of all categories ) how can i get the slug of every categorie in the loop, to verify if it exists or not in the user meta field so i can follow ( add it ) unfollow (remove it)
(

 $term = get_queried_object();

wok fine in single archive page but not in a loop of all categories)
thank you

#1269747

Hence this issue is about the Custom Logic retrieving the data - with which we can help only limitedly.

Now, in a View listing Taxonomies, you can return Term data, such as the ID of the term, or it's slug, etc.
In a Form, you can insert Fields that will populate the content edited.

Hence, you can simply add the field (user field) to the Form, and hide it with HTML/CSS (as elaborated in the previous reply).
Complete it's Field default value parameter with a ShortCode, presumably it will be the Term Slug ShortCode like [wpv-taxonomy-slug].
This is a ShortCode usually used in a View Loop of Taxonomies to display the Term Slug.
Hence if you now insert your form to a view listing taxonomies then the custom field in the form will be populated by [wpv-taxonomy-slug].
That is the term slug, so you don't need the custom code anymore.

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();

Note that $WP_Views should return a lot of other interesting things for Custom Coding if you look at it while viewing a View on the front end 😉

#1279163
toolset.jpg

Hi Beda
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" )

#1279283

Can you please set up a Testing site, where we can edit code, disable plugins and change themes, so to configure the script properly together?

Please add the links where the forms are and where the data is stored which is involved.
I will need FTP access as well, just in case.

Please make sure it's a testing site, as things may break temporarily while adjusting the code.
I've enabled a private reply so you can add the details.

#1280521

My issue is resolved now. Thank you!

Thank you

#1280523

My issue is resolved now. Thank you!