This topic contains 10 replies, has 2 voices, and was last updated by  irene 3 years, 4 months ago.

  • Author
    Posts
  • #5705

    irene
    Participant

    Hello,
    I have used this function and at first it worked just fine, but now, updated to last beta version, I have a small problem.
    Only the first letter of the new title is pulled in as title 🙁

    I do not understand what is going wrong….

    My code:

    add_filter('piklist_empty_post_title', 'my_dog_title', 10, 2);
      function my_dog_title($data, $post_array)
      {
    
        // Grab the new title from the custom field. Replace my_custom_field with your own
        $new_title = $post_array['_post_meta']['geregistreerde_naam'][0];
    
        // Only filter on your custom post type. Replace my_custom_cpt with your own.
        return $post_array['post_type'] == 'dog' ? $new_title : $post_array['post_title'];
      }

    Using the Dutch version of wp, so already changed the class-piklist-cpt to:

     public static function wp_insert_post_data($data, $post_array)
      {
        if (($data['post_status'] != 'auto-draft') && (($data['post_title'] == __('Auto Draft')) || empty($data['post_title'])))
        {
    

    according to a post here on the forum…

    This is how it shows now in the list page…, on the post itself it shows just fine…(backend-side)
    see attachement.

    Hope you can help me!
    Thanks
    Irene

    Attachments:
    You must be logged in to view attached files.
  • #5716

    Steve
    Keymaster

    If you output the $new_title to the screen, do you see the whole thing?

    add_filter('piklist_empty_post_title', 'my_dog_title', 10, 2);
      function my_dog_title($data, $post_array)
      {
    
        // Grab the new title from the custom field. Replace my_custom_field with your own
        $new_title = $post_array['_post_meta']['geregistreerde_naam'][0];
    
        print_r($new_title); // output
        die();
    
        // Only filter on your custom post type. Replace my_custom_cpt with your own.
        return $post_array['post_type'] == 'dog' ? $new_title : $post_array['post_title'];
      }
    
  • #5730

    irene
    Participant

    Hi Steve,
    I am on a localhost, do not know if this influences anything, but if I put in the line of code you give me I get a blanc screen…
    (Hope I am doing things the way I should…)

  • #5732

    Steve
    Keymaster

    Localhost shouldn’t effect it. Make sure you have not typos, and enable wp_debug.

  • #5733

    irene
    Participant

    I get just the first letter of the word!

  • #5737

    Steve
    Keymaster

    Yeah! This code is wrong:

    $post_array['_post_meta']['geregistreerde_naam'][0];
    

    Recheck the $post_array to find the value you need:

    print_r($post_array);

  • #5738

    irene
    Participant

    I am so sorry I do not see what is wrong or which value I do need 🙁
    Maybe you can direct me so I can understand where I should look for, also handy for the future…

    The output is as follow:

    Array ( [post_author] => 1 [post_content] => [post_content_filtered] => [post_title] => Automatische concepten [post_excerpt] =>[post_status] => publish [post_type] => dog [comment_status] => closed [ping_status] => closed [post_password] => [to_ping] =>[pinged] => [post_parent] => 0 [menu_order] => 0 [guid] => http://localhost:8888/fokker2/?post_type=dog&p=431 [import_id] => 0[context] => [ID] => 431 [post_date] => 2016-01-25 20:18:13 [post_date_gmt] => [post_name] => [post_modified] => 2016-01-25 20:18:03[post_modified_gmt] => 0000-00-00 00:00:00 [post_mime_type] => [comment_count] => 0 [ancestors] => Array ( ) [post_category]=> Array ( ) [tags_input] => Array ( ) [_wpnonce] => 9133725c53 [_wp_http_referer] => /fokker2/wp-admin/post-new.php?post_type=dog[user_ID] => 1 [action] => editpost [originalaction] => editpost [original_post_status] => auto-draft[referredby] => http://localhost:8888/fokker2/wp-admin/edit.php?post_type=dog [_wp_original_http_referer] => http://localhost:8888/fokker2/wp-admin edit.php?post_type=dog [auto_draft] => 1 [post_ID] => 431 [meta-box-order-nonce] => eed8522ce1 [closedpostboxesnonce] => f05b01e313[hidden_post_status] => draft [original_publish] => Publiceren [publish] => Publiceren [_post_meta] => Array ([geregistreerde_naam] => Missy [male] => Array ( [0] => option2 ) ) [_] => Array ( [nonce] => 711408066e [fields] =>bd8b22853016e1a07d301ef541ad2a8a ) [filter] => db )

  • #5739

    Steve
    Keymaster

    Guessing you want the name?

    $post_array['_post_meta']['geregistreerde_naam'];
    
  • #5742

    irene
    Participant

    Hi Steve,
    Thanks for all the trouble you took to help me out but[‘geregistreerde_naam’], is just what I used… So that can not be it. I have tried to change the name of the custom field but that did not help. I am going to reconstruct everything from base and maybe I will then find out what I did change/misspelled…
    I will let you know what I found if you would like so…
    Thanks,
    Irene

  • #5743

    Steve
    Keymaster

    The example you gave did not use ['geregistreerde_naam'], it accessed the array within it…[0]

  • #5748

    irene
    Participant

    Hello Steve,
    Fixed it!!!
    I messed up my folder structure :$
    Thanks for al your time!

    Have a nice evening,
    greetings Irene

The topic ‘empty post title does not replace all of the title…’ is closed to new replies.