for example my custom type slug is typeA, how do I get the post author, post id? I want to get the author to display the avatar.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Wei,
Thank you for getting in touch.
For clarity you are asking how to get the Post Author by using the custom post's slug or ID?
Please let me know.
Thanks,
Shane
I want to get post_id and post_author from the current post.
Below is what I want to achieve. It works
function post_author_avatar_48_shortcode(){
global $post;
$post_author = $post->post_author;
$post_id = $post->post_ID;
$author = get_the_author($post_id);
//return $post_author . " ID: " . $post_id . " author ID: " . $author;
return get_wp_user_avatar($post_author, '48');
}
add_shortcode('get_post_author_avatar_48','original_author_name_shortcode');
the above code works on wordpress post, but didn't work on toolset custom post type.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Wei,
Based on what I see this should work on custom post types. I remade your shortcode as there was some errors with the function call but this should work on your site.
// Add Shortcode
function user_current_avatar_func() {
global $post;
$post_author = $post->post_author;
$post_id = $post->post_ID;
$author = get_the_author($post_id);
//return $post_author . " ID: " . $post_id . " author ID: " . $author;
return get_wp_user_avatar($post_author, '48');
}
add_shortcode( 'get_current_author_avatar', 'user_current_avatar_func' );
The shortcode that you should use is [get_current_author_avatar]
Thanks,
Shane
My issue is resolved now. Thank you!