- This topic has 7 replies, 2 voices, and was last updated 2 years, 9 months ago by
devr52.
-
AuthorPosts
-
-
May 1, 2019 at 9:20 pm #9370
devr52ParticipantWithout piklist, the save_post action hook is called after both the post and the post’s meta fields have been saved.
When using a piklist form (FEF), it would seem that the save_post action hook is now called only after the post has been saved, but /before/ the piklist meta fields have been saved.
This is kind of breaking with the piklist philosophy of “do it the wordpress way”.
Furthermore, I cannot seem to find in the documentation or here in the forum a list of piklist action hooks to know which hook to use to replace ‘save_post’ (or ‘save_post_{cpt}’) after /piklist forms/ have saved all the post meta field data.How is this achieved?
-
May 1, 2019 at 10:59 pm #9372
devr52ParticipantI’ve tried piklist_save_field, but for some reason it doesn’t work–it’s also getting called before the meta data is saved.
I’ve even set my handler for piklist_save_field to be added from within the wp save_post action hook–which is called after the post is saved. When my hook is called this way the post meta still comes back empty–the db confirms the meta hasn’t been saved if I stop it here. If I let the handler return and the process complete the meta is saved correctly to the db–afterwards…
-
May 2, 2019 at 3:01 pm #9373
devr52ParticipantSame thing occurs with the wp_insert_post hook. The post data is available, but the meta fields are not saved yet.
-
May 3, 2019 at 10:54 am #9375
SteveKeymasterhave you tried changing the priority of your function so it’s called later?
-
May 3, 2019 at 11:02 am #9376
devr52ParticipantYes. I’ve also checked all the registered callbacks on the hooks, everything looks fine.
-
May 6, 2019 at 11:43 am #9379
devr52ParticipantHad to edit
class-piklist-form.phpand adddo_action('piklist_fields_saved');at the end of the save() method and marshall the arguments from thewp_insert_post handlerto its handler.e.g.
add_action('wp_insert_post', 'insert_handler', 100, 3); function insert_handler($post_id, $post, $update) { if ( $post->post_type != 'my_post_type') return; add_action('piklist_fields_saved', function($scope, $fields) use($post_id, $post, $update) { do_action('my_handler', $post_id, $post, $update); }, 10, 2); } -
May 6, 2019 at 12:36 pm #9380
SteveKeymasterCan you explain what you are trying to accomplish?
-
May 6, 2019 at 12:44 pm #9382
devr52ParticipantA CPT isn’t complete w/o all its fields. My handler is for after the entire CPT has been saved so that it can do stuff with it.
I want
my_handlercalled after bothwp_insert_posthas happened and all the meta fields have been saved, so that inside the handler I can:$meta = get_post_meta($post_id); // ... do stuff with both $post and $meta
-
-
AuthorPosts
- You must be logged in to reply to this topic.