• troyhallisey

    (@twarrior3dc)


    It seems that bulk_edit_posts calls the wp_insert_post (in turn calling any save_post callback before the Post Format is updated. Is this really by design or is it a bug? It seems this makes it impossible to utilize get_post_format from within a save_post callback because it won’t work when using Bulk Edit as it will return the old post format. Maybe my logic is wrong?

    Edit: Adding reference. bulk_edit_posts. See lines 559 and 568/569

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I think it is by design because if the post save should fail then related meta and taxonomy changes should not happen. I know this mechanism does not exist in bulk edit. I speak in general terms. In other processes meta and taxonomy changes always happen after post save.

    Your case is a niche case that no one apparently had foreseen. While this is unfortunate, it does not make it a bug. Rather you need to be more creative in getting your situation to work for you within the confines of the core code as it is. If you are truly stuck with no possible alternative, you may have a case for suggesting an improvement. I’m not yet convinced you are truly stuck yet.

    If you really need to capture a change in format, perhaps ‘save_post’ isn’t the best hook anyway, merely a convenient hook. Maybe there’s a more logical approach through ‘set_object_terms’ where your callback looks for particular conditions before doing anything.

    Thread Starter troyhallisey

    (@twarrior3dc)

    Thanks for the response. No I am not really stuck. I have already added

    if ( isset( $_REQUEST['post_format'] ) && $_REQUEST['post_format'] != -1 ) {
    	set_post_format($post_id, $_REQUEST['post_format']);
    }

    to my callback before I need to use get_post_format. This just checks if the post format var is set and not equal to the No Change option from the select menu. It seems like this is such as easy solution that I am not sure why its not designed like that to begin with.

    Also I am using save_post because I am using a metabox to save some custom data and then sync that data and WP core data to an external database when the post is published or updated (and Bulk Edited). Though I agree with you that I can’t possibly be the first person ever needing to use get_post_format in a save_post callback.

    The Codex says that save_post is always called after the post is updated as well, but since this is obviously not always the case (as in post_format and also the sticky status just below wp_update_post in the referece), it seems misleading to say that. If its by design it should be at least referenced in the codex as an exception.

    Moderator bcworkz

    (@bcworkz)

    Well, the Codex is literally correct in that the post entry in the post table is updated immediately before ‘save_post’ fires. I agree that not yet updating peripheral values as well is confusing. FYI, anyone registered for www.ads-software.com can edit the Codex, so if you wish to make things clearer by all means do so ??

    Unfortunately the Codex is not getting much love these days because the documentation team is focused on a replacement reference. Still, it currently is the best reference available for many things despite its shortcomings and it continues to be used extensively by many people. A clarification would not be a wasted effort.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Updated post format not available from within save_post callback using Bulk Edit’ is closed to new replies.