Skip Navigation

[Resolved] Post Form (CRED) Permalink

This support ticket is created 5 years, 3 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 10 replies, has 2 voices.

Last updated by Shane 5 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#1512827

Tell us what you are trying to do?

I made a post form, I have a snippet to update the post title from the custom fields (title, name, surname).
Everythings works well, but the permalink still looks like this "specialiste_sps=cred-auto-draft-feb2e5fd3f52612416233352093c51ad"

Is it possible to make the permalink from custom fields?

I´ve read multiple support threads but couldn´t make it work.

I use this snippet for Post form:

add_action('cred_save_data','func_generate_automatic_post_title', 10, 3);
function func_generate_automatic_post_title($post_id,$form_data) {

if ($form_data['id']==4505 or $form_data['id']==4519) {

$types_fields = get_option('wpcf-fields');
$sps_titul = $types_fields['sps_titul']['data']['options'];

$all_opt = array();
foreach($sps_titul as $k=>$v):
$all_opt[$v['value']] = $v['title'];
endforeach;

$name = get_post_meta($post_id, 'wpcf-sps_jmeno', true);
$surname = get_post_meta($post_id, 'wpcf-sps_prijmeni', true);
$titul = get_post_meta($post_id, 'wpcf-sps_titul', true);
$title= $all_opt[$titul]." ".$name." ".$surname;
$args = array('ID' => $post_id, 'post_title' => $title);
wp_update_post($args);
}
}

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

hidden link

Thank you in advance!

Best Regards

David

#1513135

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thank you for getting in touch.

Could you let me know what kind of field you are trying to get the post title from ?

Thanks,
Shane

#1513443

Hi Shane,

the post title is made by the post form like this:

wpcf.sps_jmeno (text custom field), wpcf-sps_prijmeni (text custom field) and wpcf-sps_titul (select custom field)

It would be great if the permalink was made from the same fields as the post title, but if it gets the things complicated I would be ok just with the two text custom fields I mentioned above.

Thank you!

Regards

David

#1513499

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Could you try it simple like this at first then we go from there?

// Neutral Names Autogenerate Post Title
 
function func_generate_automatic_post_title( $post_id, $post ){
 
if ($form_data['id']==4505 or $form_data['id']==4519) {

 
  $name = get_post_meta($post_id, 'wpcf-sps_jmeno', true);

$args = array('ID' => $post_id, 'post_title' => $name);
wp_update_post($args);

        wp_update_post( $args );
 
  }
}
add_action( 'cred_save_data', 'func_generate_automatic_post_title', 30, 2 );
//

Try this and let me know if it works.

Thanks,
Shane

#1513513

Hi Shane,

Unfortunately, it doesn't.

I tested on demo (clone) site and when adding to functions.php:

Your PHP code changes were rolled back due to an error on line 30 of file wp-content/toolset-customizations/toolset-custom-code.php. Please fix and try saving again.

Cannot redeclare func_generate_automatic_post_title() (previously declared in wp-content/themes/SPSMv02/functions.php:73)

When adding as custom code snippet via Toolset:

"There has been a critical error on your website."

Regards

David

#1513519

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Could you mind allowing me to have admin access to the website so that I can work on this for you?

Please let me know the page where the form is located as well.

Thanks,
Shane

#1513527

Hi Shane,

I couldn't find the private message option in my response form.

This is for the test site on a different domain:

I have also one for the edit form and one I use for the administrator to be able to add this custom post as I didn't figure out how to make post titles from custom fields from the back-end as well. 🙂

Thank you!

David

#1513567

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thank you for the patience,

The code below should provide a suitable example for you.

function func_generate_automatic_post_title( $post_id, $form_data ){
  
if ($form_data['id']==4505 or $form_data['id']==4519) {
 
  
  $name = sanitize_title( get_post_meta($post_id, 'wpcf-sps_jmeno', true));
 
$args = array('ID' => $post_id, 'post_name' => $name);
wp_update_post($args);
   
  }
}
add_action( 'cred_save_data', 'func_generate_automatic_post_title', 30, 2 );

I've tested this and it works fine.

Thanks,
Shane

#1513633

Thanks for the directions!
You saved me a lot of hours, much appreciated!

My issue is resolved now. Thank you!

#1514303

Hey Shane,

Can I reopen the ticket?

I didn´t test it properly.

The code updates slug but now the post title is CRED Draft...

I need them both - post title from cred as well as slug from cred.

Thank you

David

#1515215

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Try it like this.


function func_generate_automatic_post_title( $post_id, $form_data ){
   
if ($form_data['id']==4505 or $form_data['id']==4519) {
  
 $surname = get_post_meta($post_id, 'wpcf-sps_prijmeni', true);
  $name = sanitize_title( get_post_meta($post_id, 'wpcf-sps_jmeno', true));
  
$args = array('ID' => $post_id,'post_title'=>$surname 'post_name' => $name);
wp_update_post($args);
    
  }
}
add_action( 'cred_save_data', 'func_generate_automatic_post_title', 30, 2 );

This should serve as a suitable example for you.