marinig
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Function for adding a term to a taxonomyHi, try this:
wp_insert_term
Codex Page for info:
http://codex.wordpress.org/Function_Reference/wp_insert_termHope this help
Forum: Fixing WordPress
In reply to: Error 404 on pagination when changing posts_per_page on query_postsI 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
Forum: Fixing WordPress
In reply to: Error 404 on pagination when changing posts_per_page on query_postsUp 🙂
Forum: Fixing WordPress
In reply to: Error 404 on pagination when changing posts_per_page on query_postsI 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.
ThanksForum: Fixing WordPress
In reply to: Error 404 on pagination when changing posts_per_page on query_postsHelp please!