Skip Navigation

[Resolved] Automatically fill post title

This support ticket is created 6 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 10 replies, has 2 voices.

Last updated by Noman 6 years, 8 months ago.

Assisted by: Noman.

Author
Posts
#618533

Tell us what you are trying to do? I am trying to automatically fill the post title.

Is there any documentation that you are following? I have been looking around here at the technical support related answers.

Is there a similar example that we can see? No

What is the link to your site? hidden link and to the specific page hidden link

I have tried this code:

[code]
// VUL POST TITLE

function my_save_data_action($post_id, $form_data){
// Change your CRED Form "ID" accordingly below
if ($form_data['id']==48){

//Declare the content of your variables, change "your_custom_field_slug" accordingly
$custom_title = get_post_meta( $post_id, 'wpcf_aankoopdatum, true );

//collect data and define new title
$my_post = array(
'ID' => $post_id,
'post_title' => $custom_title,
'post_name' => $custom_title,

);

// Update the post into the database
wp_update_post( $my_post );

}
}
add_action('cred_save_data', 'my_save_data_action',10,2);
[/code]

The cred form has the id of 48 and 'aankoopdatum' is a custom field in that post type used in the form.

But end up seeing a blank page.

If you want to log in let me know.

#618605

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Jos,

Thank you for contacting Toolset support. There is syntax error in your code. Here is updated code:

// VUL POST TITLE
function my_save_data_action($post_id, $form_data){
	// Change your CRED Form "ID" accordingly below
	if ($form_data['id']==48){
	
	//Declare the content of your variables, change "your_custom_field_slug" accordingly
	$custom_title = get_post_meta( $post_id, 'wpcf_aankoopdatum', true );
	
	//collect data and define new title
	$my_post = array(
		'ID' => $post_id,
		'post_title' => $custom_title,
		'post_name' => $custom_title,
	);
	
	// Update the post into the database
	wp_update_post( $my_post );
	
	}
}
add_action('cred_save_data', 'my_save_data_action',10,2);

I hope it will fix blank page issue.

Thank you

#618607

Noman,
Thank you for your quick reaction. No luck though, the page will not display.
Any idea?

#618698

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Jos,

Please enable error reporting by adding following code in your wp-config.php file:

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );

// Disable display of errors and warnings 
define( 'WP_DEBUG_DISPLAY', true );
@ini_set( 'display_errors', 1 );

// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );

https://codex.wordpress.org/Debugging_in_WordPress

So, that we can see error details.

Thank you

#618829
toolset2.jpg
toolset1.jpg

Hello Noman,

I put the code back in and the page displayed. Strange. But the title is not automatically filled.
I have changed the wp-config.php as you said I should, but cannot find the /wp-content/debug.log file.

What is going wrong?

#618895

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Jos,

For further debug, provide temporary access WP-Admin Login and FTP login info to your site. Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

Thank you

#618965

Hi Nomen,

Only the date is enough.

Jos

#618970

Noman,

I realise it is better WITH the name. Excuse me for the confusion.

Jos

#619089

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Jos,

I have replaced ‘wpcf_aankoopdatum’ with ‘wpcf-aankoopdatum’ and issue is gone. Can you please check and confirm?

Here is doc for more details:
https://toolset.com/documentation/customizing-sites-using-php/functions/

Thank you

#619102

Hi Noman,

Thanks so far. But then I have a (hopefully) final question. How can I convert this number to an understandable date?

#619143

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Date.png

Hello Jos,

Date field return following information as an array:

array(6) {
  ["display-only"]=>
  string(16) "23 February 2018"
  ["datepicker"]=>
  string(10) "1519344000"
  ["datetime"]=>
  string(10) "2018-02-23"
  ["hour"]=>
  string(2) "00"
  ["minute"]=>
  string(2) "00"
  ["timestamp"]=>
  int(1519344000)
}

We can use ‘display-only’ index in your case. I have updated following code:

$custom_title = get_post_meta( $post_id, 'wpcf-aankoopdatum', true );

With:

$custom_title = $_POST['wpcf-aankoopdatum']['display-only'];

And now date format looks fine as in attached screenshot.

Thank you