Skip Navigation

[Resuelto] I want to use cred_before_save_data with taxonomy term names

This support ticket is created hace 7 años, 2 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: ,

Este tema contiene 3 respuestas, tiene 2 mensajes.

Última actualización por Beda hace 7 años, 2 meses.

Asistido por: Beda.

Autor
Mensajes
#568539

I would like to use cred_before_save_data to concatenate some text (set by value attribute in CRED) and the term names from selected from two taxonomies and make the result the post title.

Portion of my CRED form:
[code]
[cred_field field='post_title' post='event' value='Kamloops vs ' urlparam='' class='form-control' readonly='true' output='bootstrap']
[cred_field field='team' display='checkbox' display='select' single_select='true' output='bootstrap']
[cred_field field='event-category' display='select' single_select='true' output='bootstrap']
[/code]

I understand that the php would look something like:
[code]
add_action('cred_save_data', 'build_title', 10, 2);
function build_title($post_id, $formdata)
{
// if a specific form
if ($form_data['id']==64)
{
$field1=get_post_meta($post_id, 'wpv-taxonomy1name');
$field2=get_post_meta($post_id, 'wpv-taxonomy2name');
}
$post_title="$field1 $field2";
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title));
}
[/code]

But I'm not sure how to put it all together. What the variable names of the selected taxonomy terms would be.

#568586

with get_post_meta() you get... post meta.
https://developer.wordpress.org/reference/functions/get_post_meta/

To get terms, you need another function.
wp_get_post_terms() will help you to get all terms of a certain taxonomy added to a certain Post ID.
https://codex.wordpress.org/Function_Reference/wp_get_post_terms

get_the_terms is similar:
https://developer.wordpress.org/reference/functions/get_the_terms/

With that, you should be able to proceed.

#568913

I feel like someone just handed me a bucket of parts and called it a toaster.

#569000

I'm sorry, Darryl, we do not provide custom code in the forum.
https://toolset.com/toolset-support-policy/

What we provide is information how you can do it, we can look at code and test or reccomend better approaches, and so on.
But we cannot deliver ready to use code.

With the above elaborated function you can get the terms.
With this, you can then use wp_update_post and construct the Post Title with the data you got previously.

As example, if you want to update a Post Title with a Custom Field you would use this code:
https://pastebin.com/2BTbVbcs

If you want to add more values, you need to get them first (with above elaborated Function) and then concatenate them (.=) with PHP to create a new Title.

You can also use the $_POST.
This holds all information of the Form itself, before you submit it.
You can access $_POST data by using $_POST['form-field-slug'].

That can then be used to populate a PHP $variable, wich later you can use in the wp_update_post() function.