Skip Navigation

[Resolved] CRED auto title on post update?

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Bruno Simon 6 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#527371

I am trying to: Regenerate post title on post update

I visited this URL: https://toolset.com/forums/topic/get-custom-taxonomy-in-auto-title/

I expected to see:

Instead, I got:

Hello, In above ticket, I was succesfully helped to auto-generate CPT title based on different custom taxonomy and fields.
It seems however that when I update those taxonomy/fields while editing the post, the title is not updated on saving (updating) the post.
Any hint would be welcome.
Thanks.

#527389

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Bruno

I set up a quick test site to check this (I can see no reason from the code samples in the linked ticket why it would not work) and found that editing the post using CRED and changing the taxonomy terms the post title was updated accordingly.

This may be a silly question but did you modify your code so that it also runs on the edit CRED form and not just the CRED form to publish new content (i.e. that it checks the $form_data['id'] against the id of both forms)?

#527587

Hi Nigel,

Erm, actually far from being silly, your question is right to the point; I just forgot to adapt my function.php file accordingly since I am indeed using two different forms for create and edit.
Still, with the following new code, it still does not work :

//* CRED autotitle
add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data) {
  if ($form_data['id']==1279) {
    $term_list = wp_get_post_terms($post_id, 'listing-type', array("fields" => "names","orderby"=>"term_id"));    
    $auctiontype = join("-",$term_list);
    $auctiondate = get_post_meta($post_id, 'wpcf-auction-ending', true);
    $auctiondate = date('j F Y',$auctiondate);
    $dayofweek = date('l', strtotime($auctiondate));
    $term_list= wp_get_post_terms($post_id, 'car-brand', array("fields" => "names","orderby"=>"term_id"));
    $carbrand = join(" ",$term_list);
  
    $title= $auctiontype. ': ' .$dayofweek. ' ' .$auctiondate. ' - ' .$carbrand;
    $args = array('ID' => $post_id, 'post_title' => $title);
    wp_update_post($args);
 if ($form_data['id']==1417) {
    $term_list = wp_get_post_terms($post_id, 'listing-type', array("fields" => "names","orderby"=>"term_id"));    
    $auctiontype = join("-",$term_list);
    $auctiondate = get_post_meta($post_id, 'wpcf-auction-ending', true);
    $auctiondate = date('j F Y',$auctiondate);
    $dayofweek = date('l', strtotime($auctiondate));
    $term_list= wp_get_post_terms($post_id, 'car-brand', array("fields" => "names","orderby"=>"term_id"));
    $carbrand = join(" ",$term_list);
  
    $title= $auctiontype. ': ' .$dayofweek. ' ' .$auctiondate. ' - ' .$carbrand;
    $args = array('ID' => $post_id, 'post_title' => $title);
    wp_update_post($args);
     }
  }
}

What am i missing?

#527752

Hi,
It eventually worked (one closing bracket was misplaced).
Thanks for your time.

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.