Site logo

Archived topic

Author of CPTs

9 replies · Started by Raul on May 11, 2022

Viewing posts 1–10 of 10

Hi

I have created a custom post type with PODS and have created a relationship of authors with the Users.

I think that the theme has the ability to show all posts (CPTs) of an author when someone clicks on their names? At least, this is what I'd like.
Could you please give me some directions? I'm totally lost at this point on how I could achieve this.

Hi Raul,

Give this PHP snippet a try:

add_action( 'pre_get_posts', 'add_cpt_author_archives' );
function add_cpt_author_archives( $query ) {
	
	if ( ! $query->is_main_query() || is_admin() || ! is_author() ) {
		return;
	} 

	$query->set( 'post_type', array( 'post', 'movie' ) ); 
}

Replace moviewith your CPT slug.

Thank you. I know to add a code snippet, but I don't know how this helps me.

I do not know how to have a link that leads to the author's archive of CPTs :(
I'm beginner in WordPress but I guess I miss something obvious/easy?

Hi there,

default author archives are found here: /author eg.

https://www.yourdomainname.com/author/abc/

Ah, I see. I have tested that without the code snippet of your colleague, which now makes sense.

I still need to know how I can output such generic links, according to the author. (Like "domain.com/slug?author=youclickedthis")

Sorry, not "generic", but... if I have hundreds of authors, I need to know what link was clicked (on which of the authors)...

You would need to get the author archive link in your Custom post type. Might want to check with PODs support how to do that.

That is enabled. I just don't know how to set the dynamic links. Someone click on an author/item etc. to be redirected to the respective author/item.

Indeed, it was a simple solution; I just had a blind spot. I have found it. Thank you for the help.

Glad to hear you found the solution

This archived topic is closed to new replies.