[wp-hackers] Help with controlling search result (posts_per_page)
codehooligans at codehooligans.com
Tue Jun 13 21:32:22 GMT 2006
Happy Tuesday all,
I posted this earlier for the WP Support but no answer.
A client wants to limit the number or items returned for a search
result page to 5 items. I've looked through the classes.php code and
see the use of 'posts_per_page'. I can see where the default value is
set from the options. I don't want to change the site-wide result,
just on this page.
So I've added a hidden form field of this name to my search form. Set
the value to 5. When I search I still get the default of 10. I've
tried to trace through the code and cannot determin what I'm doing
My WP is 2.0.2. Here is my form code:
<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<input type="text" class="textbox" name="s" id="s" value="<?php echo
wp_specialchars($s, 1); ?>" />
<input type="hidden" class="textbox" name="posts_per_page"
id="posts_per_page" value="5" />
<input type="image" alt="go" class="imgbutton" name="imageField"
src="<?php bloginfo('template_url'); ?>/images/gosearchbutton.jpg" />
Any thoughts? I really want to keep this clean if possible. Meaning I
don't want to write a plugin just for this. Also I don't want to re-
call get_posts from my search.php page. To me this would be double-
processing the search.
More information about the wp-hackers