Custom metabox for author not author ID
-
Hi,
I am trying to add a custom meta-box for author name on my wordpress, however when I select an existing user, it outputs as the user ID, and not the author’s name.
Is there an easy solution to my problem?
My code is as follows:
add_filter( 'the_author', 'replace_author_name' ); add_filter( 'get_the_author_display_name', 'replace_author_name' ); function replace_author_name( $name ) { global $post; $author = get_post_meta( $post->ID, 'replace-author', true ); if ( $author ) $name = $author; return $name; }
add_filter( 'rwmb_meta_boxes', 'your_prefix_meta_boxes' ); function your_prefix_meta_boxes( $meta_boxes ) { $meta_boxes[] = array( 'title' => __( 'Select an author', 'textdomain' ), 'post_types' => 'post', 'fields' => array( array( 'id' => 'replace-author', 'name' => __( 'Select an existing author (if not yourself)'), 'desc' => __( 'Use this if you are uploading the news story on behalf of another author', 'textdomain' ), 'type' => 'user', 'field_type' => 'select_advanced', 'placeholder' => 'click here to change the author;', ), array( 'id' => 'guest-author', 'name' => __( 'Or type a guest Author', 'textdomain' ), 'type' => 'text', ), array( 'id' => 'copyright', 'name' => __( 'Who owns the copyright?', 'textdomain' ), 'desc' => __( 'No copyright will display if this box is left blank', 'textdomain' ), 'type' => 'text', ), ), ); return $meta_boxes; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Custom metabox for author not author ID’ is closed to new replies.