Support » Fixing WordPress » Including meta data when using query_posts

  • Resolved octonaut

    (@octonaut)


    This may be a little complicated to explain, but I’ll do my best.

    Basically, I’m creating bio pages for all the authors on my website. The pages use a template called “Bio Page”. I don’t want to create a new template for every single author—I just want to use the same one.

    The problem is that I also want to have, say, a “Recent Works” section at the bottom of the bio, displaying the last five posts by that specific author. It would seem that the easiest way to go about this is to define the person’s name in a custom field, and simply have query_posts call from that custom field. But how would I do this?

    Put simply, I need query_posts to be fluid and to adapt to different author names based on the same “Bio Page” template.

    I’ve tried to use get_post_meta within query_posts, but it broke instantly (as I thought it might). I’m stuck. Help!

    Thank you so much in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,

    Rather than using a page template, you might be better off taking advantage of the built in template hierarchy by using the author.php template.

    The advantage of this is that no custom fields are required and the query you describe is set up for you automatically by WordPress.

    Here’s an example of a site using the author.php template. As you can see, it displays some info about the author, followed by their posts.

    Perhaps take a look at the author.php templates included with the default Twenty Ten and Twenty Eleven themes as a starting point.

    Thread Starter octonaut

    (@octonaut)

    Thank you! But how would I then access my author archives page, if it searches for author.php first? I rely on those.

    So, you want author bio pages (that display a biography and five recent posts) and separate author archives (that display all posts by an author)?

    Would it not make sense to combine these (using author.php), or have I misunderstood?

    Thread Starter octonaut

    (@octonaut)

    Well, yes—but only because of how robust the author archives are.

    See here: http://www.viiinothing.com/author/john/

    I want to link to this archive on the actual bio page. The bio page is just kind of a landing page for everything associated with the author. Does that make more sense? I understand why it would sound redundant . . .

    Also, thank you again for spending some of your Sunday afternoon helping me.

    Ok, well your original idea of using a page template should probably do the trick.

    I’ve posted a basic template here that, I think, accomplishes what you’re looking for. It looks for a custom field in the page called author_name.

    I’ve put some comments in the code that should explain how it works.

    You’ll probably need to add in containing <div>s and suchlike, so that it fits correctly with your theme, but hopefully it provides a starting point.

    Thread Starter octonaut

    (@octonaut)

    Ross,

    Thank you so much! I got it working with your code.

    Would you mind taking a look at my other thread? http://wordpress.org/support/topic/creating-a-master-archive?replies=3

    It’s something not too far off from what you’ve done here . . . but again, I can’t figure it out.

    Thanks again.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Including meta data when using query_posts’ is closed to new replies.