• Resolved sierrakilogulf

    (@sierrakilogulf)


    I am trying to display multiple custom post types in an author archive page, but can’t seem to get both a CPT and post to display (handled by loops in elementor). I can only get one or the other, and only one CPT.

    I have been able to get my singular CPT to display using the code provided:

    function wpse107459_add_cpt_author( $query ) {
        if ( is_admin() || ! $query->is_main_query() ) {
        	return;
        } 
    
        if ( $query->is_author() ) {
            $query->set( 'post_type', array( 'MY_CPT_1' ) );
        }
    
    }
    add_action( 'pre_get_posts', 'wpse107459_add_cpt_author' );

    Where do I go from here to get this to work with multiple custom post types and the posts?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If the output is being handled by Elementor modules, then you’ll probably want to reach out to Elementor support since I don’t believe those are what are considered the “main query” for those archives, thus the sample above wouldn’t have any effect. They’ll better know how to modify their module queries to include extra post types.

    For the sake of thoroughness and curiosity, your case is using Elementor to help handle the display of say https://www.MYSITE.com/author/sierrakilogulf/ as an example? That’d be the author archive where the code above should play its part.

    Also just in case, you should be specifying the post types like this:

    $query->set( 'post_type', array( 'MY_CPT_1', 'post' ) );
    
    Thread Starter sierrakilogulf

    (@sierrakilogulf)

    I will reach out to the Elementor team as well, although the code I supplied above was the only way I’ve been able to display CPT for author archives using ele. It works great if I only needed to display one type, but I want to be able to display more than just one Custom Post Type in the archive, organized with templates. With this code, we can only display one CPT or posts, not both. We are using Ele Custom Skin and a few other plugins to achieve what we are after but due to the changed code above, we can only display one type despite adding our templates for other CPT’s.

    I changed the permalink structure slightly. in the case of our website the author used to be at http://www.example.com/author/username but what we are trying to achieve is http://www.example.com/gardeners/username/my-journals where the authors journal entries page is a tab in the buddypress profile.

    We managed to get author links redirected to the user profile, but can’t for the life of us manage to get multiple (or even singular) CPT’s displayed in the new tab in the buddypress menus. Might be a bit above my head but I won’t rest till I figure it out! lol

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    We’re rootin for ya, and definitely an interesting mix from what you note above. I should probably aim to learn Elementor a bit more, as we do get our fair amount of page builder questions going on.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Displaying Custom Post Types in Author Archives’ is closed to new replies.