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 creating a related post article feature for my wordpress enabled site.being new to php and wordpress facing some issue. though i can user wordpress build in feature to show related post of author but since site is hosting articles of authors who don't have any profile with us and there are many such authors so when a new post is being created for the author we tend to save a custom field as author_email. so based on this we want to show all post being published of a particual author.i tried using get_posts() method

<?php 
        $args = array( 'meta_key' => 'author_email', 'meta_value' => 'XYZ@XYZ.com');
        $authorposts=get_posts($args); ?>
    <div id="content">
    <span class="breadcrumbs"><a href="<?php echo get_option('home'); ?>/">Home</a> &raquo; <?php the_category(', ') ?></span>
    <?php if (count( $authorposts ) > 0) {
    foreach ( $authorposts as $post ): setup_postdata($post)            ?>
    <div id="headline_author">
        /*
          showing post tilte with image and some part of it
        */
        <div class="clearfloat"></div>
    </div>
    <?php endforeach;  ?>
    <div class="post-nav">
                <div class="previous"><?php previous_posts_link('&lsaquo; Previous Page') ?></div>
                <div class="next"><?php next_posts_link('Next Page &rsaquo;') ?></div>
    </div>
   <?php
                    } else {
                        echo '<p>No articles by this user</p>';
                    }       
                    ?>
</div>

it showing the first 5 results and a link to the next page but when i click on the next page it show me that it has gone to second page as its also visible on the URL but its showing the same 5 results what it has shown in the first page. i am an idea that the query i have written on the same page is getting executed again from the beginning but not sure how to fix it. since i am using cutom fields to get posts i can use simple query to fetch post based on the limit or offse etc.

can any one help me to fix the things or can point me hw to do it in right way

thanks in advance

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

I think you need to tell that the query is paged.

Did you tried :

 $args = array( 'meta_key' => 'author_email', 'meta_value' => 'XYZ@XYZ.com', 'paged' => $paged);

?

share|improve this answer
    
:thanks i figuered it out, acceting your answer so that if some one faceing similar issue can benifits from it :) –  Umesh Awasthi Nov 20 '11 at 8:44
add comment

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.