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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0