Tagged: CPT, empty post title
- This topic has 10 replies, 2 voices, and was last updated 6 years ago by
irene.
-
AuthorPosts
-
-
January 24, 2016 at 10:54 am #5705
ireneMemberHello,
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
IreneAttachments:
You must be logged in to view attached files. -
January 25, 2016 at 12:10 pm #5716
SteveKeymasterIf 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']; } -
January 25, 2016 at 12:54 pm #5730
ireneMemberHi 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…) -
January 25, 2016 at 1:26 pm #5732
SteveKeymasterLocalhost shouldn’t effect it. Make sure you have not typos, and enable wp_debug.
-
January 25, 2016 at 1:58 pm #5733
ireneMemberI get just the first letter of the word!
-
January 25, 2016 at 3:01 pm #5737
SteveKeymasterYeah! This code is wrong:
$post_array['_post_meta']['geregistreerde_naam'][0];
Recheck the
$post_arrayto find the value you need:print_r($post_array); -
January 25, 2016 at 3:20 pm #5738
ireneMemberI 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 )
-
January 25, 2016 at 3:45 pm #5739
SteveKeymasterGuessing you want the name?
$post_array['_post_meta']['geregistreerde_naam'];
-
January 25, 2016 at 4:26 pm #5742
ireneMemberHi 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 -
January 25, 2016 at 4:29 pm #5743
SteveKeymasterThe example you gave did not use
['geregistreerde_naam'], it accessed the array within it…[0] -
January 25, 2016 at 6:20 pm #5748
ireneMemberHello Steve,
Fixed it!!!
I messed up my folder structure :$
Thanks for al your time!Have a nice evening,
greetings Irene
-
-
AuthorPosts
- The topic ‘empty post title does not replace all of the title…’ is closed to new replies.