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 14 down vote accepted

I'm almost sure that author is built-in so use somthing like author_more

so you need to add that var to query_vars first

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

add_filter('init', 'add_author_more_query_var');

then on your moreauthorposts.php call it like this:

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

Update

this works in the http://domain.com/index.php?author_more=value

but if you want to use this as fancy url you need to add a rewrite rule

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

add_action('init','add_author_more_rewrite_rule');

and now you can use http://domain.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.