Skip Navigation

[Resolved] Using get_post_meta in cred_save_data

This support ticket is created 2 years, 6 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 21 replies, has 2 voices.

Last updated by nicolaS-3 2 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#2377323

Hi Shane
I tried different versions, none of them works, there must be some kind of en error:

$age = do_shortcode( "[wpv-post-taxonomy item='".$post->ID."' type='ages' separator=',' format='name'  ]");
$age = do_shortcode( "[wpv-post-taxonomy item='".$post->ID."' type='ages' separator=',' format='term_name'  ]");
$age = do_shortcode( "[wpv-post-taxonomy item='".$post_id."' type='ages' separator=',' format='name'  ]");

FYI the slug of the Ages taxonomy is user-age, not sure if it matters ...
thanks
Nicola

#2377425

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nicola,

The slug actually matters because if the correct taxonomy slug isn't being used then you won't get anything from the shortcode.

Replace ages with user-age in the shortcode and let me know if you start getting the results.

If this doesn't work please provide me with the step by step instructions on how to test this on your site so that I can have a look at it.

Thanks,
Shane

#2378721
EXCERPT2.png

Hi Shane,
I tested the following code:

  $age = do_shortcode( "[wpv-post-taxonomy item='".$post->ID."' type='user-age' separator=',' format='name'  ]");

and it actually works, BUT what happens is that it creates a new post instead of updating the existing one. The form is in edit mode (but I am planning to use the same code also in add mode). All fields of the existing user profile are updated correctly by the form if changed, but excerpt that is updated correctly (including age) in a newly created post where all other fields are empty ! in the user interface the existing profile is given as correctly updated but another empty form is added for the new post below the message ! see screenshot.
Why this happens ? how can it be that a form in edit mode creates a new post ?
thanks
Regards
Nicola

#2378909

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nicola,

Glad to see the code is now working to some extent.

Some debugging is needed here. What I recommend doing now is to remove the code or deactivate it. Test the update form again to see if a new post is created. Then re-add your code line by line of course keeping the parts that will allow it to function in its basic form.

Alternatively can you paste your final code here so that I can see exactly what is being used? I tried looking for the function on your site but wasn't able to find it.

Thanks,
Shane

#2378927

Hi Shane,
I saw your access. You didn't find the code because I am testing it on localhost. Now I have added the code to the online site for you to see it, but it's inactive because I am afraid it could crash the site (I am not a debugging wizard either ...).
I can guarantee that without that code the form works perfectly, no post duplication. In order to test the snippet you need to update the first two fields of the form (type and age) connecting as a non-admin user and check if the Excerpt field is filled.
Thanks
Nicola

#2378963

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nicola,

I believe I've spot the issue with the code.

Can you test this one below and let me know if the issue still remains.

add_action('cred_save_data','write_excerpt_profiles',10,2);
function write_excerpt_profiles($post_id,$form_data) {
	if ($form_data['id']==1312) {

	$gender = types_render_field("user-gender", array('item'=> $post_id ));
	$type = types_render_field("user-main-type", array('item'=> $post_id ));
	$gruppi = types_render_field("favorite-bands", array('item'=> $post_id ));
/**
	$age = apply_filters( 'get_the_terms', $age, $post_id, 'ages' );
      
	$prov = apply_filters( 'get_the_terms', $prov, $post_id, 'geo' );
 */
  $age = do_shortcode( "[wpv-post-taxonomy item='".$post_id."' type='user-age' separator=',' format='name'  ]");
  
	$excerpt= $type . ", " . $gender . ", " . $phone2 . ", " . $age . ", " . $prov . ", " . $gruppi;
	$args = array('ID' => $post_id, 'post_excerpt' => $excerpt);
	wp_update_post($args);
	}
}

Thanks,
Shane

#2379017

My issue is resolved now. Thank you!