Skip Navigation

[Resolved] I tried to follow the past support solutions to code that cannot be execut

This support ticket is created 4 years, 11 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by Minesh 4 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1955971

Tell us what you are trying to do?
I tried to follow the past support solutions to code that cannot be executed.

Is there any documentation that you are following?

https://toolset.com/forums/topic/add-auto-generate-post-title-from-fields/

Is there a similar example that we can see?

/**
* Auto-generate post title
*/
function trace_autogenerate_title( $post_id, $post ){

if ( 'bildungsangebot' == $post->post_type ) {

$pd_sku = get_post_meta( $post_id, 'wpcf-product_sku', true );
$pd_sn = get_post_meta( $post_id, 'wpcf-serial_number', true );

$new_title = $pd_sku . " " . $pd_sn . " " .$post_id ;
$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', 'trace_autogenerate_title',30,2);

// update the post, which calls save_post again
wp_update_post( $args );

// re-hook this function
add_action('save_post', 'trace_autogenerate_title',30,2);

}
}
add_action( 'save_post', 'sha_autogenerate_title', 30, 2 );

What is the link to your site?
removed

#1955999

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Toolset offers the "Custom Code" section where you can add your custom code. So, I've moved the code you added to your current theme's functions.php file to "Custom Code" section:
=> hidden link

Then, I see you have done everything ok but you just forget to change the post type slug.

So, I've changed the following line of code from:

if ( 'bildungsangebot' == $post->post_type ) {

To

if ( 'product-traces' == $post->post_type ) {

That will help to target your correct post type and I can see its working as expected now.

#1961601
截圖 2021-02-21 下午9.51.26.png
截圖 2021-02-21 下午9.49.47.png
截圖 2021-02-21 下午9.49.03.png

Thanks for your help. this problem has been solved.

I have another problem. I add the URL field. I use the button to display and set the URL as a dynamic link, but it cannot work.

#1962271

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to know that your original issue is addressed.

May I kindly request you to open a new ticket with every new question you may have. This will help other users searching on the forum as well as help us to write correct problem resolution summery for the original issue reported. Thank you for understanding.

#1962415

My issue is resolved now. Thank you!
I agree to make it public.But, I do not know how to open.

Can you help me delete personal information such as the authorized URL of the website in these conversations?

#1962469

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

What information you want to delete?

#1962475

My issue is resolved now. Thank you!

#1962481

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - i've removed those from the initial reply and make the other reply private so it will not be accessible publicly.