• I’m currently writing a plugin which should do something while saving a post if the post belongs to the default category.

    At that time the following strange behaviour got my focus:

    Approach 1:
    1. Click on “Add” / “New” to create a new post
    2. Type in a title
    3. Put the mouse pointer into the editor

    The buttons “Save”, “Publish” etc. immediately change to bright (disabled) while WordPress performs an AJAX request and back to normal style. After that:

    4. Click on one of the category checkboxes OTHER than the default category.

    The category is now selected AFTER the AJAX request.

    5. Save or publish the post to trigger my plugin’s action at the hook ‘save_post’.

    Approach 2, in another order:
    1. Click on “Add” / “New” to create a new post
    2. Type in a title
    3. The cursor stays in the title field. Click with the mouse pointer on one of the category checkboxes OTHER than the default category.

    The category is now selected BEFORE the AJAX request.

    And now WP performs an AJAX request. The buttons like “Save” or “Publish” immediately are bright (disabled) during the request and back. After that:

    4. Save or publish the post to trigger the my plugin’s action at the hook ‘save_post’.

    Same same, but different?
    Although both approaches seems “to be the same” the results are different:

    Although both posts do not belong to the default category the approach 1 let my plugin at hook ‘save_post’ think post 1 belongs to the default category and so it does something.

    So it is defined somewhere that post 1 is related to the default category even if the user selected another category until the post is saved.

    My aim is to take approach 1 to the same result as approach 2. How can this be reached? What to catch or to avoid?

  • The topic ‘Strange result while saving a new post’ is closed to new replies.