[Resolved] Author of CPTs

Home Forums Support [Resolved] Author of CPTs

Home Forums Support Author of CPTs

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2216780
    Raul

    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.

    #2216810
    Ying
    Staff
    Customer Support

    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.

    #2217171
    Raul

    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?

    #2217353
    David
    Staff
    Customer Support

    Hi there,

    default author archives are found here: /author eg.

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

    #2217409
    Raul

    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“)

    #2217410
    Raul

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

    #2217491
    David
    Staff
    Customer Support

    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.

    #2217505
    Raul

    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.

    #2217761
    Raul

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

    #2218248
    David
    Staff
    Customer Support

    Glad to hear you found the solution

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.