Iâve created a custom post type for employees in a company with some fields they have to fill (like E-mail, phone, etc.) and a select box which takes some values from another custom post type called âcompanyâ.
Iâve disabled / removed the editor for the employee post type but now Iâm having trouble listing them in the overview because each âemployeeâ misses a title (post_title).
How can I set the post_title for an employee to be equal to the custom field âNameâ?
There is a lot of code working so Iâll only show the part where Iâm saving my data for each employee:
foreach ($meta_box['fields'] as $field) {
if(isset($_POST[$field['id']])) {
if(!add_post_meta($post_id, $field['id'], $_POST[$field['id']], true)) update_post_meta($post_id, $field['id'], $_POST[$field['id']]);
}
}
I have an array with all the data and then save with the right values for each field but can I here say, that:
If($field[âidâ] == âemp_nameâ) {
Set($post_title = $field[âidâ]);
}
Or something like that?
Any help or suggestions would be very much appreciated.
Thank you
– Mestika
I would simply filter
the_title
so that it outputs the appropriate custom-field data for your custom post type:This will replace the post title with the value for custom field “name” for your custom post type. If no “name” is entered, it returns “(Name Not Entered)”.
(Of course, you’ll need to replace the values for
get_post_type()
and$custom['name']
, as appropriate.)