Skip Navigation

[Resuelto] Current post title in CRED notification

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I have a CRED form that creates new posts. I have placed the form in a template and I would like to capture the title of the post where the CRED form is shown, and include that in an email notification.

Solution: You can use a generic field in the CRED form and set the value of the generic field to the title of the current post:

[cred_generic_field field='currentpagetitle' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[wpv-post-title id='$current_page']",
"persist":1
}
[/cred_generic_field]

Then you can access the currentpagetitle field in an email notification using a custom placeholder %%CURRENT_PAGE_TITLE%% by adding the following code to functions.php:

add_filter('cred_body_notification_codes', 'custom_generic_field_notification');
add_filter('cred_subject_notification_codes', 'custom_generic_field_notification');
 
function custom_generic_field_notification( $defaultPlaceHolders ) {
 
  $newPlaceHolders = array(
    '%%CURRENT_PAGE_TITLE%%' => $_REQUEST['currentpagetitle']
  );
 
  return array_merge($defaultPlaceHolders, $newPlaceHolders );
}

Relevant Documentation:
https://toolset.com/documentation/user-guides/how-to-use-custom-placeholders-in-cred-notifications/

This support ticket is created hace 6 años, 6 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
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)

Etiquetado: 

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por Pat hace 6 años, 6 meses.

Asistido por: Christian Cox.

Autor
Mensajes
#902404

Pat

Hello,

I have created a Cred notification. This Cred is displayed on the postype (objet) page. This Cred creates another postype (message) and is used to allow visitors to get in touch with the owner of the object by sending a message.

I have a issue there : I need to retrieve the post title of the object (ie : the post title of the object page) and if I'm using the [wpv-post-title] shorcode, it returns the title of the created message and not the title of the object.

Any idea?
Regards
Pat

#902442

Hi Pat, you can use a generic field in the CRED form and set the value of the generic field to the title of the current post:

[cred_generic_field field='currentpagetitle' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[wpv-post-title id='$current_page']",
"persist":1
}
[/cred_generic_field]

Then you can access the currentpagetitle field in an email notification using a custom placeholder %%CURRENT_PAGE_TITLE%% by adding the following code to functions.php:

add_filter('cred_body_notification_codes', 'custom_generic_field_notification');
add_filter('cred_subject_notification_codes', 'custom_generic_field_notification');

function custom_generic_field_notification( $defaultPlaceHolders ) {

  $newPlaceHolders = array(
    '%%CURRENT_PAGE_TITLE%%' => $_REQUEST['currentpagetitle']
  );

  return array_merge($defaultPlaceHolders, $newPlaceHolders );
}
#902744

Pat

Hi Christian,

Perfect
Many thanks
Regards
Pat