Thread Starter
fatalx
(@fatalx)
I also looked into using
wp_update_post
but since I’m using a hook I it causes the browser to timeout.
Any thoughts?
Thread Starter
fatalx
(@fatalx)
Well I fixed my problem. In the end
add_filter('title_save_pre','my_function');
worked perfectly fine. The problem was that my function was calling the custom fields from
global $post
and when the post is first published those custom fields have not been written to $post yet.
So you have to use
$_POST['your custom field']
to properly grab your post title.
Hope this helps someone.
This method caused problems for me in WordPress 3.1, but its possible that I didn’t handle the 'title_save_pre'
filter correctly.
I’ve set up a custom post type “Testimonial”, and I want the post title to be defined by the custom “Client” meta field, and I don’t want the title editor to be available.
In the end, I want $post->post_title == get_post_custom($post->ID)["client"][0]
Could you show me what the ‘my_function’ method should look like when you bind it to the ‘title_save_pre’ filter?
Thanks for the post – its been hard to find other information on this topic.
Thread Starter
fatalx
(@fatalx)
Response 3 months later haha sry but for anyone coming across this again the ‘my_function’ function is really simple all it has to do is return a value. The returned value will be the title.
So if I wanted to grab some meta data that the user entered and make that my title it would look like this.
function my_function(){
$meta_data = $_POST['meta_name'];
return $meta_data;
}
You can perform any operation you wish on the title inside that function.
Hey fatalx,
How did you alter the title for the custom post type? If we were not using any meta content. I have this snippet which is currently not working for me. Mind helping please?
add_filter('the_title', 'new_title');
function new_title($title) {
global $post, $post_ID;
$title['custom_version'] = 'Application Name v'.$title;
return $title;
}