Skip Navigation

[Resolved] Get current custom type post author, post id

This support ticket is created 4 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by WeiS2074 4 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#1676489

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.

#1677025

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

#1677325

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.

#1678067

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

#1678637

My issue is resolved now. Thank you!