Skip Navigation

[Résolu] Auto Draft

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.

This topic contains 7 réponses, has 2 voix.

Last updated by Adriano Il y a 7 années et 7 mois.

Assigned support staff: Adriano.

Auteur
Publications
#214465

Hi

I have created a custom post type with no Title and I would like one of the custom fields to be the title. Currently, it does save the posts as Auto Draft with no title.

How can I make a custom field A title that does not save as Auto Draft and also be able to use [wpv-post-link] short code?

Thanks

#214517

Dear James,

The custom code below should works for you:

function post_updated( $post_id ) {
         
        $my_post = array(
           'ID'           => $post_id,
           'post_title' => get_post_meta( $post_id, 'custom_field', true ),
        );
 
        wp_update_post( $my_post );     
}
add_action( 'save_post', 'post_updated' );

My code is using the default action by WordPress, save_post: http://codex.wordpress.org/Plugin_API/Action_Reference/save_post

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#214792

Hi Adriano

I have to say that I am not good at coding.
I have added the below function to the functions.php file of the theme.
I does not allow me even to add a new custom post and it gives an Apache error.

function post_updated( $post_id ) {

$my_post = array(
'ID' => $post_id,
'post_title' => get_post_meta( $post_id, 'wpcf-business-name', true),
);

wp_update_post( $my_post );
}
add_action( 'save_post', 'post_updated' );

I am not sure what I am doing wrong?

Thanks

#214863

Dear James,

Right, let's try another WordPress hook:

add_filter('title_save_pre', 'save_title');
function save_title($my_post_title) {
        if ($_POST['post_type'] == 'post_type_name') :
          $new_title = $_POST['custom_field_name'];
          $my_post_title = $new_title;
        endif;
        return $my_post_title;
}

So, you just need to replace "post_type_name" with the slug name of this post type, "custom_field_name" with the custom field name, of course including "wpcf-" prefix.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#214984

Hi Adriano

I have tried it but it didn't work. Now it allows me to add the post but creates it with "no title".

add_filter('title_save_pre', 'save_title');
function save_title($my_post_title) {
if ($_POST['post_type'] == 'merchant') :
$new_title = $_POST['wpcf-business-name'];
$my_post_title = $new_title;
endif;
return $my_post_title;
}

Thanks

#215134

Dear James,

Please replace your code with this below, it should works:

add_filter('title_save_pre', 'save_title');
function save_title($my_post_title) {
if ($_POST['post_type'] == 'merchant') :
$new_title = $_POST['wpcf']['business-name'];
$my_post_title = $new_title;
endif;
return $my_post_title;
}

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#215146

Thanks mate.
It's perfect

#215148

You are welcome.