• Resolved alibenmoussa

    (@alibenmoussa)


    Add this code in theme file functions.php

    function allowCoursesAuthorEditing()
    {
        if(current_user_can('administrator')){
            add_post_type_support( 'courses', 'author' );
        }
    }
    
    add_action('init','allowCoursesAuthorEditing');
Viewing 3 replies - 1 through 3 (of 3 total)
  • Doesn’t work for me ?? when I save the author switches back on page refresh.

    • This reply was modified 4 years, 8 months ago by 360fun.

    Doesn’t work, the author not change.

    Thread Starter alibenmoussa

    (@alibenmoussa)

    Sorry The end is missing.

    The full code below works for me from admin:

    
    function allowCoursesAuthorEditing()
    {
        if(current_user_can('administrator')){
            add_post_type_support( 'courses', 'author' );
        }
    }
    
    add_action('init','allowCoursesAuthorEditing');
    
    function coursesAuthor($data , $postarr){
        global $wpdb;
    
        $courses_post_type = 'courses'; // type of custom post type tutor course
        $post_ID = $postarr['ID']; // ID OF POST
        $post_author = $postarr['post_author'];  POST TYPE
    
        if ($data['post_type'] === $courses_post_type){
            if ($post_author > 0){
                $data['post_author'] = $post_author;
            }else{
                $data['post_author'] = get_current_user_id();
            }
        }
    
        return $data;
    }
    
    add_filter('wp_insert_post_data', 'coursesAuthor', '99', 2);
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘change author/instructor for Admin’ is closed to new replies.