• Resolved Iperdesign_IT

    (@iperdesign_it)


    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    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');

    Thread Starter Iperdesign_IT

    (@iperdesign_it)

    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?

    Moderator keesiemeijer

    (@keesiemeijer)

    Try clearing your browsers cache and deleting cookies.

    Thread Starter Iperdesign_IT

    (@iperdesign_it)

    Try clearing your browsers cache and deleting cookies.

    Thanks! Now it is working! ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Change post categories on post saving’ is closed to new replies.