WordPress.org

Forums

[resolved] [Twenty Twelve] Display both Posts & Pages on Author Page (3 posts)

  1. bobmeier
    Member
    Posted 2 years ago #

    Greetings!
    I've recently started using a theme that does not have its own author.php template. I've managed to create one using the author template from the Twenty Twelve theme and it works as it should, showing all posts created by the author.

    However, I actually want the author page to show not only the Posts, but also the Pages created by the author. I thought this would be explained for the Twenty Twelve (or Eleven or Ten) Theme somewhere on the Internet but I couldn't find anything.
    So I'm wondering, is this even possible or does the function to display all Pages from an Author simply do not exist?

    Any help is appreciated!
    All the best,
    Bobmeier

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Try it with this in your theme's functions.php:

    function author_post_and_pages( $query ) {
      // not an admin page and is the main query
      if ( !is_admin() && $query->is_main_query() ) {
        if( is_author() ){
          $query->set( 'post_type', array('post', 'page') );
        }
      }
    }
    add_action( 'pre_get_posts', 'author_post_and_pages' );

    btw:
    consider creating a child theme instead of editing your theme directly - if you upgrade the theme all your modifications will be lost.

  3. bobmeier
    Member
    Posted 2 years ago #

    Took me a while to try it out, but thank you so much - works like a charm!

    I gotta say, I really apreciate the WordPress Community for always providing help so quickly and spot-on!

Topic Closed

This topic has been closed to new replies.

About this Topic