• Resolved yasiph

    (@yasiph)


    What if I want to display first name in specific posts which contain a custom field?

    I’m focusing on a child theme on twentyten amd on parent functions.php
    get_author_posts_url( get_the_author_meta( 'ID' ) )

    How do i get it display first name with the link to author posts?

Viewing 4 replies - 1 through 4 (of 4 total)
  • try get_the_author_meta( 'first_name' , 'ID')

    of course, ID should be the actual user ID

    Thread Starter yasiph

    (@yasiph)

    @trepmal How would that work?
    Changed this

    function twentyten_posted_on() {
    	printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    		'meta-prep meta-prep-author',
    		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
    			get_permalink(),
    			esc_attr( get_the_time() ),
    			get_the_date()
    		),
    		sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
    			get_author_posts_url( get_the_author_meta( 'ID' ) ),
    			sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
    			get_the_author()
    		)
    	);
    }

    to

    function twentyten_posted_on() {
    	printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    		'meta-prep meta-prep-author',
    		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
    			get_permalink(),
    			esc_attr( get_the_time() ),
    			get_the_date()
    		),
    		sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
    			get_author_posts_url( get_the_author_meta( 'first_name' , 'ID' ) ),
    			sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
    			get_the_author()
    		)
    	);
    }

    And author post url is wrong. Changes …?author=1 to …?author=0

    Sorry, I think I was up too late trying to answer questions… ??

    Maybe this:

    function twentyten_posted_on() {
    	printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    		'meta-prep meta-prep-author',
    		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
    			get_permalink(),
    			esc_attr( get_the_time() ),
    			get_the_date()
    		),
    		sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
    			get_author_posts_url( get_the_author_meta( 'ID' ) ),
    			sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
    			get_the_author_meta('first_name')
    		)
    	);
    }

    If that doesn’t work, my guess would be that the author-related functions aren’t getting the author ID to work with… I might find a way to pass it the id

    function twentyten_posted_on( $id ) {
    	printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    		'meta-prep meta-prep-author',
    		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
    			get_permalink(),
    			esc_attr( get_the_time() ),
    			get_the_date()
    		),
    		sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
    			get_author_posts_url( $id ),
    			sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
    			get_the_author_meta('first_name', $id)
    		)
    	);
    }

    and when the function is called,
    twentyten_posted_on( get_the_author_meta( 'ID' ) );

    Thread Starter yasiph

    (@yasiph)

    Excellent! Managed to change the Nicename to first name(needed this function in multi-lingual posts) Thanks @trepmal

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display first name in specific posts which contain a custom field’ is closed to new replies.