Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have two authors pages, one displays about 5 posts. Then I'm trying to setup another page that will be all of their posts. I have created a template called moreauthorposts.php and I'm trying to pass the author variable to this page. Problem is if i pass domain.com/more-author-posts?author=johndoe it gets stripped out. How can I retrieve this value? Is this even possible in wordpress? I know WP Rewrite is jacking my URL structure somehow I'm just not sure.

I've tried:

get_query_var('author')

and tried reading this but didn't have any luck:

http://codex.wordpress.org/Query_Overview

Suggestions?

Thanks.

share|improve this question

1 Answer 1

up vote 15 down vote accepted

I'm almost sure that author is built-in, so use something like author_more. You will need to add that var to query_vars first. Example:

// add `author_more` to query vars
add_filter( 'init', 'add_author_more_query_var' );
function add_author_more_query_var()
{
    global $wp;
    $wp->add_query_var( 'author_more' );
}

Then on your more-author-posts.php template call it like this:

if ( get_query_var( 'author_more' ) )
{
    // do your stuff
}

Update

This works in the following URl example/use case:

http://example.com/index.php?author_more=value

But if you want to use this as fancy URl, you need to add a rewrite rule:

add_action('init','add_author_more_rewrite_rule');
function add_author_more_rewrite_rule()
{
    add_rewrite_rule(
        'more-author-posts/(\d*)$',
        'index.php?author_more=$matches[1]',
        'top'
    );
}

Now you can use it like this

http://example.com/more-author-posts/value
share|improve this answer
    
Ok so I added the query vars into the functions.php. Then added the other code to my more author posts. What would be the correct URL structure to pass these through? I know that paged uses the format of /page/2 but doing more-author-posts/more_author/johndoe doesnt' seem to be working? –  codeisforeva Jan 31 '11 at 20:03
    
i updated the answer –  Bainternet Jan 31 '11 at 20:32
    
Problem is im not trying to pass the vars to index.php. Im trying to pass them to the custom template I have developed since it looks completely different from index. So if I pass values to moreauthor.php?author_more=johndoe .. that doesnt seem to work. Doing something wrong here? –  codeisforeva Jan 31 '11 at 20:46
    
@בניית אתרים looks like a very clear answer! @codeisforeva You shouldn't be calling the template file directly, should you? index.php is just the root file of wordpress, every rewrite rule should go through there. –  goldenapples Jan 31 '11 at 22:20
1  
@codeisforeva: The index.php in the rewrite rule is the index.php in the root directory of WordPress, not the index.php in your template file. You can still choose which template should be displayed, by hooking into the template_include filter. –  Jan Fabry Feb 7 '11 at 17:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.