• Documentation
  • Support / Community
  • Products
    • Piklist Framework
    • Toolbox
    • Fields and Forms
    • WordPress Helpers
  • Log In
Piklist

Access your account, and post on the Support Forums

Retrieve Password | Register for account

Topic: save_post action hook replacement?

Support Home » Topics » Piklist » save_post action hook replacement?

Tagged: FEF save_post action hook meta data

  • This topic has 7 replies, 2 voices, and was last updated 2 years, 9 months ago by devr52.
Viewing 7 reply threads
  • Author
    Posts
    • May 1, 2019 at 9:20 pm #9370
      devr52
      Participant

      Without 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
      devr52
      Participant

      I’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
      devr52
      Participant

      Same 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
      Steve
      Keymaster

      have you tried changing the priority of your function so it’s called later?

    • May 3, 2019 at 11:02 am #9376
      devr52
      Participant

      Yes. I’ve also checked all the registered callbacks on the hooks, everything looks fine.

    • May 6, 2019 at 11:43 am #9379
      devr52
      Participant

      Had to edit class-piklist-form.php and add do_action('piklist_fields_saved'); at the end of the save() method and marshall the arguments from the wp_insert_post handler to 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
      Steve
      Keymaster

      Can you explain what you are trying to accomplish?

    • May 6, 2019 at 12:44 pm #9382
      devr52
      Participant

      A 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_handler called after both wp_insert_post has 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
  • Author
    Posts
Viewing 7 reply threads
  • You must be logged in to reply to this topic.
Log In

Log in / Register

Register for an Account

Stay up-to-date with Piklist

About

  • Philosophy
  • Privacy Policy
  • Terms of Service
  • Contact Us
  • Register for an account

Resources

  • Community Forums
  • Documentation
  • Tutorials
  • Get involved

Follow Piklist

  • Like us on Facebook
  • Follow us on Twitter
  • Connect on Google +
  • Watch on YouTube

Rate Piklist


If you love Piklist leave us a 5 Star review on WordPress.org.

News

  • Piklist v0.9.9.8 is now available

    September 30, 2019

    In October of 2015, we released v0.9.9 of Piklist. Your help in testing lead to seven(7) m ...

  • Piklist is now on HackerOne

    September 30, 2019

    We built Piklist from the ground up with security as our top priority. While we’ve t ...

  • Read all News
  • Powered by Piklist & WordPress © 2009 – 2022 Piklist LLC.
    This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to the use of cookies. Find out more.