Passing and retrieving query vars in wordpress

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

Leave a Comment