This topic has 4 replies, 2 voices, and was last updated 9 years by jorasik.

  • Author

    Tagged: ,

  • #45295
     jorasik
    Participant

    How can I modify the author.php to include posts from two custom post types?
    A bit new to all the PHP stuff so I would appreciate if someone can help me with that issue.

    #45297
     sharmstr
    Moderator

    google http://designpx.com/tutorials/custom-post-types-author-archive/

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #45382
     jorasik
    Participant

    Yes, i already tried google and adding to the function.php the snipped of code with my custom post types, for some reason it is not working.

    By default i assume it should fall to archive.php the one which is in the parent theme. Not working for me. I added an author.php with the same structure and it is not working too.

    Any suggestions or directions?

    #45396
     sharmstr
    Moderator

    My cpts show up in the author archive (archive.php site.com/author/authorname). So maybe its how your cpt is set up. Do they actually support Authors? For example, Kleos Testimonials and Clients are both CPTs, but they do not have Authors. http://codex.wordpress.org/Function_Reference/register_post_type

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #45399
     jorasik
    Participant

    I just managed to do it. It was a small mistake in the function from the first link. Now it works just fine for getting the author posts.

    Here is what I am using, maybe someone else will need it too.

    COPY CODE
    function custom_post_author_archive($query) {
        if ($query->is_author)
            $query->set( 'post_type', array('posttype1', 'posttype2') );
    	return $query;
        remove_action( 'pre_get_posts', 'custom_post_author_archive' );
    	
    }
    add_action('pre_get_posts', 'custom_post_author_archive');
Viewing 5 posts - 1 through 5 (of 5 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?