WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Change post categories on post saving (5 posts)

  1. Iperdesign_IT
    Member
    Posted 3 years ago #

    Hi,

    I have to update post categories on save. I use

    add_action( 'save_post', 'saving' );

    code, and inside the functions i tryed a lot of built-in wordpress functions such as:

    wp_set_post_categories,
    wp_set_object_terms,
    wp_update_post

    Still nothing. After the page is reloaded, categories are always the same. Are there any other functions to set categories to a specified post on save?

    Thanks.

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    This works for me:

    function set_my_categories($post_ID){
    if(wp_is_post_autosave($post_ID) || wp_is_post_revision($post_ID)) {
      return $post_ID;
    }
    wp_set_post_categories( $post_ID, array(49,13) );
    }
    add_action('save_post', 'set_my_categories');
  3. Iperdesign_IT
    Member
    Posted 3 years ago #

    This works for me:

    function set_my_categories($post_ID){
    if(wp_is_post_autosave($post_ID) || wp_is_post_revision($post_ID)) {
      return $post_ID;
    }
    wp_set_post_categories( $post_ID, array(49,13) );
    }
    add_action('save_post', 'set_my_categories');

    Thanks, but when the page loaded ( after save ), i need to reload to see categories setted. Any idea to avoid this refresh?

  4. keesiemeijer
    moderator
    Posted 3 years ago #

    Try clearing your browsers cache and deleting cookies.

  5. Iperdesign_IT
    Member
    Posted 3 years ago #

    Try clearing your browsers cache and deleting cookies.

    Thanks! Now it is working! ;)

Topic Closed

This topic has been closed to new replies.

About this Topic