I have created a custom post type with name Courses. Also i have created a custom fields in it.
I dont want to use WordPress default title field and visual editor for this custom post type only.
I have remove visual editor from custom post edit section but not able to remove or hide default title fields.
Now following things i want to do:-
1. Remove or hide default title field for only custom post type.
2. Use a custom field value as title. (Automatically put a custom field value in title, whenever we see all post section it show that custom field value as title but do not show when we edit or create a new post in that custom post type.).
3. In short, when we save a post , custom field value goes into title field no matter field is filled or not.
Hello. Thank you for contacting the Toolset support.
First of all, I would like to know that you want to remove the default post title field when you add/edit the post from backend admin - is that correct? If yes, if you want to disable the default post title field then you should just edit your post type from Toolset => Post Types => Edit your post type => deselect the checkbox for title field from the section "Sections to display when editing ".
When i save or publish first time then its giving me error that date() expects parameter 2 to be integer, string given
But when i refresh error page its working fine and putting custom-field value in title field.
Do you have any clue that why its giving error for first time and working fine on refresh?
Can you please check and let me know if code need some modification?
Please help me to solve this.
The hook you are using is a WordPress hook. In addition to that, I see you added single quotes to priority '10', you need to add without single quotes 10 to your hook.
function swp_autogenerate_title( $post_id, $post ){
if ( 'course-apply' == $post->post_type ) {
$starts = get_post_meta($post_id,'wpcf-starting-date',true);
$starts= date('M j', $starts);
$ends = get_post_meta($post_id, 'wpcf-ending-date' , true);
$ends= date('M j, Y', $ends);
$waht_for = get_post_meta($post_id, 'wpcf-for' , true);
$new_title = $starts.' - ' . $ends.' ('.$waht_for.')';
$new_title = sanitize_text_field( $new_title );
$new_slug = sanitize_title( $new_title );
$args = array(
'ID' => $post_id,
'post_title' => $new_title,
'post_name' => $new_slug
);
// unhook this function so it doesn't loop infinitely
remove_action('save_post', 'swp_autogenerate_title',30,2);
// update the post, which calls save_post again
wp_update_post( $args );
// re-hook this function
add_action('save_post', 'swp_autogenerate_title',30,2);
}
}
add_action( 'save_post', 'swp_autogenerate_title', 30, 2 );
But still its giving warning on load that
Warning: date() expects parameter 2 to be int, string given
But working fine on publish.
Please help me to solve this.
I'm not sure why you are getting that notice. What if you disable the save_post action - do you still get the notice? If yes, I need a problem URL and access details to check things on your install.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I checked with my local test install and I do not see any warning when I try to add a new post which is having a custom date field created using Types plugin. Please check the screenshot: hidden link
Either you can send me access details or duplicator package with problem URL where I can see the issue or I'm afraid I can not do much here.
I have set the next reply to private which means only you and I have access to it.