Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi, try this:

    wp_insert_term

    Codex Page for info:
    http://codex.ww.wp.xz.cn/Function_Reference/wp_insert_term

    Hope this help

    Thread Starter marinig

    (@marinig)

    I think this topic may interest many wordpress users. So please, help!

    You can see the bug in action:
    1) make a fresh install of your favorite versione of wordpress
    2) create a new category
    3) insert, say, 9 posts in this category
    4) go to admin > settings > reading and set to 10 the numer of posts showed on each page (global posts_per_page setting)
    5) Open archive.php in a text editor and write this code at the beginning:

    <?php
    global $query_string;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($query_string.'&paged='.$paged.'&posts_per_page=3');
    ?>

    6) Open the category on your browser and try to go on to second page and you will get the 404 error.

    Is there something wrong with the query?

    Thanks

    Thread Starter marinig

    (@marinig)

    Up 🙂

    Thread Starter marinig

    (@marinig)

    I did some debug and found out something interesting.
    I put at the end of the 404 template file a print_r($wp_query); and discovered that after clicking on the “next page” link on the first archive page, the posts_per_page variable is set back to the default value (that set on the admin settings page).
    In other words my setting of the posts_per_page variable written at the beginning of the archive template is completely ignored and somehow lost.
    Still I don’t know why this happens…

    It seems that the wp_query is executed before opening the archive template where there’s the “correct” custom posts_per_page value and so, considering the default value (higher than the custom one), page 2 is non existent and then 404 error is correct…

    I managed to solve the problem using a custom url rewrite rule (put on functions.php of my template) introducing the correct posts_per_page value directly on the query string at redirect and everything goes right. But this is not a solution as I hate to change 2 different files just to change the posts_per_page setting of the custom archive page. I think there should be another and hopefully better way to do this.

    Please, tell me something.
    Thanks

    Thread Starter marinig

    (@marinig)

    Help please!

Viewing 5 replies - 1 through 5 (of 5 total)