Support » Fixing WordPress » If post is made by user role then stick his post

  • Resolved Gustav

    (@4ever16)


    Looking for a plugin or function.
    If a post was made by user role “author” then makes his post sticky.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Tri, that’s simple: please add the following function in functions.php file of your child theme:

    // automatically make post sticky 
    add_action('wp_insert_post', 'mo_make_it_sticky_if_role');
    function mo_make_it_sticky_if_role( $post_id ) {
    	if( current_user_can('author') ) {
    		stick_post( $post_id );
    	}
    }

    This will make any new post sticky if currently logged user has “author” role, right at the moment when he/she clicks Posts -> Add New.

    Hope it helps 🙂
    Alex.

    Thread Starter Gustav

    (@4ever16)

    Thanks it worked.
    And made a small adjustment so it works with all posting plugins and in the front end.

    add_action('save_post', 'mo_make_it_sticky_if_role');
    function mo_make_it_sticky_if_role( $post_id ) {
    	if( current_user_can('author') ) {
    		stick_post( $post_id );
    	}
    }
    • This reply was modified 2 years, 9 months ago by Gustav.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘If post is made by user role then stick his post’ is closed to new replies.