jamie.gordon.tt on "[Plugin: Meta Box] 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;
retu $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', ), ), ); retu $meta_boxes;
}

https://wordpress.org/plugins/meta-box/

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 207 تاريخ : چهارشنبه 29 ارديبهشت 1395 ساعت: 21:26