Support » Fixing WordPress » wp_query and pagination

  • cosimo

    (@cosimoamicagmailcom)


    Hi to all. I know my topic is already discussed in forum, but none of solutions i’ve read worked for me. I’ve spent many hours to search but i cannot resolve. I have a loop with wp_query and i cannot paginate it.

    global $wp_query;
    	$cat_id = get_query_var('cat');
    	$category_name=get_the_category_by_ID($cat_id);
    	$category_link = get_category_link($cat_id);

    Then i call the wp_query

    $paged=get_query_var('paged');
    $my_query = new WP_Query('cat='.$cat_id.'&posts_per_page=60&paged=$paged');

    Then the loop and lastly i call the pagination functions:

    next_posts_link('Next posts', $my_query->max_num_pages);
    previous_posts_link('Previous posts', $my_query->max_num_pages);

    Then reset the data for other queries

    wp_reset_postdata();

    This code seems right for me: but don’t work. On my server(localhost:8888) i have a 404 page (page not found) when i click on pagination links. On the domain of the site instead of 404 page it show always the same posts by clicking on pagination links.

    I cannot understand the problem. Please someone help me i’m getting crazy with this.

    Thank to all and excuse me for my bad english

Viewing 1 replies (of 1 total)
  • Thread Starter cosimo

    (@cosimoamicagmailcom)

    excuse me in the previous post i write wrong code:

    next_posts_link('Next posts', $my_query->max_num_pages);
    previous_posts_link('Previous posts', $my_query->max_num_pages);

    this is the exact code for pagination:

    next_posts_link('Next posts', $my_query->max_pages);
    previous_posts_link('Previous posts', $my_query->max_pages);

    it was just a digitation error.

    [ Please do not bump. It’s not permitted here. ]

Viewing 1 replies (of 1 total)
  • The topic ‘wp_query and pagination’ is closed to new replies.