0

I have an author archive page to display authors' posts. In some of the authors the pagination works, but in some cases it doesn't.

Where is the problem? Here is my code:

<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$wpfp_before = "";
echo "<div class='wpfp-span'>";

if ($wpfp_before):
echo '<div class="wpfp-page-before">'.$wpfp_before.'</div>';
endif;
$favorite_post_ids = get_user_meta($user_id, 'wpfp_favorites', true);
if ($favorite_post_ids) {
$favorite_post_ids = array_reverse($favorite_post_ids);
$post_per_page = wpfp_get_option("post_per_page");
$page = intval(get_query_var('paged'));

$qry = new wp_query(array('post_type' => 'videosprogram' ,  'post__in' => $favorite_post_ids ,'posts_per_page' => 3,'paged' => $paged ) );                      

while ($qry->have_posts() ) : $qry->the_post();


//Loop ....


endwhile; wp_pagenavi( array( 'query' => $qry ) ); ?>

UPDATE:-

i try this way :-

function cpt_on_author_page( $query ) {
    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
    //$author_name = get_post_meta($curauth->id, 'author_name', true);
    if ( $query->is_author() && $query->is_main_query() ) {
        $query->set( 'post_type', 'videosprogram' );
        $query->set( 'posts_per_page', 1 );
        $query->set( 'meta_key' , 'show_program_editors');
        $query->set( 'meta_value' , $curauth->id); 


    }
}
add_action( 'pre_get_posts', 'cpt_on_author_page' );

but not show me any post

4
  • Why aren't you using the main query? Where are you using this code? Please have a look at pre_get_posts and WP_Query. Your custom query just seems all wrong. – Pieter Goosen Jul 12 '14 at 22:22
  • no wrong in my wp_query, its get me all post but the problem is when go to page NO 2 its show me page not found – user3704392 Jul 12 '14 at 22:27
  • if the main query has no posts, then you will get a 404 regardless of the results of your query in the template. that's why you should use pre_get_posts instead. – Milo Jul 13 '14 at 4:43
  • @Milo How can use main query ,,, can you edit my query ? – user3704392 Jul 13 '14 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.