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 am trying to get posts with an author's ID as a meta value in the author.php template using additional request parameter.

For example I want posts with john's ID as a meta value using a request like this

http://localhost:8888/twitgreen/author/john/?eco=somemetakey

So far I can make it using a new WP_query in author.php like this

if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
    $paged = get_query_var('page');
} else {
    $paged = 1;
}

if($_GET['eco']=='somemetakey'){
    $lot = array(
        'meta_query' => array(
            array(
                'key' => 'somemetakey',
                'value' => $current_view->ID
            )
        ),
        'post_type'=>'lot',
        'paged'=>$paged ,
    );
}

$wp_query = new WP_Query($lot);

//and some loop here

<nav id="nav-below">
    <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'clonecell' ) ); ?></div>
    <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'clonecell' ) ); ?></div>
</nav><!-- #nav-below -->

But unfortunately it doesn't work on the next pages. The URL, http://localhost:8888/twitgreen/author/verifikator/page/2/?eco=somemetakey points to the 404 page.

The Question

  • How can I query posts with an author's ID as a meta value in the author.php?
  • How can I query posts with an authors's ID as a meta value or post from that author in author.php?
  • How can I do this requests using WordPress hooks?

Thank you in advance.

share|improve this question

2 Answers 2

Instead of a new WP_Query, use the pre_get_posts filter

add_filter('pre_get_posts', 'custom_query');
function custom_query($query) {
    if($query->is_main_query() && $query->is_author() && $_GET['eco']=='somemetakey') {
        $query->set('meta_query', array(
            array(
                'key' => 'somemetakey',
                'value' => $query->get('author')
            )
        ));
    }
}
share|improve this answer
    
I think it still need to unset the author parameter. I'll let you know if I find it in Google –  ifdion Oct 25 '12 at 5:35
up vote 0 down vote accepted

Alternative approach to answer the problem

So far I havent found any method to do that. One would be better of creating a custom page for any custom query than modifying the author.php.

share|improve this answer

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.