• [Title translated to English]

    Hello!

    I’m trying to automatically change the title of the articles for a custom post type based on a custom field that contains an ID. With the ID, I get the title to assign to the post. I found the best method for this to work. Unfortunately, I have to update twice for the title changes. It is obvious, when publishing the article, the custom field is not yet registered in the database. I should be able to recover the information before the first publication. Is it possible?

    Here is my code:

    function alter_title($t) {
      if ('tests' == get_post_type()) {
    	  foreach(get_field('fiche') as $post_object):
    	   global $title;
    	   $title = get_the_title($post_object->ID);
    	   endforeach;
      	return $title;
      }
    
    }
    
    if ('tests' == get_post_type()) {
    add_filter('pre_post_title','alter_title');
    add_filter('pre_post_name','alter_title');
    }

    [In future please wrap your code with backticks not blockquotes]

    Thank You

  • The topic ‘Retrieves the value of the meta before publishing’ is closed to new replies.