• Hello,
    the question I have is, is it possible to make more search results show up when someone searches for a keyword on my wordpress only 3 results will show up. I am guessing only 3 will show up because I have my wordpress set on the main page so that only 3 posts show at one time.

    Is there any way to set the search results higher so more results will show up without changing the amount of posts that shows up on my main page?

Viewing 9 replies - 16 through 24 (of 24 total)
  • Yes sir, and t31os_ tip in another thread did not work for the topic starter and not for me, so then he jumped in and we are testing now.

    Hi t31os_,
    Your example enduro.nl/wptest/index.php?s=wassink gives three results where the third found post does not contain the word “wassink”. They are just the three newest posts. Try “markelo” gives the same three and is not in any of them.

    2.7.1? … if it’s a test install, plonk the current version on there.

    Yes I will later but not in the next two months or so. I am in the busy season now, and have to travel abroad. No the good moment for a change; I need it to be equal now for other little tryouts. Could be a 2.7.1 related problem.
    I don’t know what the topic starter is running.
    I have 10 frontview posts and so I have 10 search results in my normal setting, so I am happy enough.

    I’ve been working on my site today, and i’ve come to realise something.

    You were indeed correct regarding search results when setting parameters inside query_posts.

    The moment you start plonking any paramters into the query, you’re over-writing the query string that has been passed into it by the search..

    So as it stands (unless i’m mistaken), you cannot adjust the search results shown, you can however view more search results by using Prev/Next links as you would with regular entries.

    So simply put, whatever you have set as “posts to show” (or whatever it’s called in the admin) will be how many results you get on the search results (per page)…

    Any adjustment to the query_posts line, will effectively re-write the query (losing the search paramters)…

    NOTES: You can see the current search query in get_query_vars('s'), and you’ll soon see any adjustment to query_posts causes the data stored there to be lost..

    There’s also other info you can look at in get_query_vars, such as posts per page, and how many results were found in the search, etc.. (and various other bits).

    Hope that clears things up a little, and i admit, i was indeed incorrect and a little fast to jump the gun before.. ??

    What about a new query? I use multiple new queries in pages and posts that work without overwriting the main loop:

    <?php $my_query = new WP_Query(''); while ($my_query->have_posts()): $my_query->the_post(); ?><?php endwhile; endif; ?>

    Some possibly helpful examples with search count parameters, but not search results.

    Ah hah!… i didn’t realise you can pass search parameters into the query, i’m going to give that a test now…

    Thanks for the link above..

    Will report back shortly..

    I suppose it makes perfect sense that the search query would work inside query_posts.. with a little reflection on what should have been obvious to begin with (lol), i’ve written an update to the code i posted before..

    <?php
    /**
     * @package WordPress
     * @subpackage Default_Theme
     */
    
    get_header(); ?>
    
    	<div id="content" class="narrowcolumn" role="main">
    
    	<?php
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$posts_per_page = 10;
    	$args = array(
    		'posts_per_page' => $posts_per_page,
    		's' => $s,
    		'paged' => $paged
    	);
    	query_posts( $args );
    
    	if (have_posts()) :
    	$page_count = $paged * $posts_per_page;
    	?>
    		<h2 class="pagetitle">Search Results</h2>
    		<h4>Showing
    		<?php
    		switch($paged) {
    			case 1 :
    				echo $page_count - $posts_per_page . ' - ';
    			break;
    			case $paged > 1 :
    				echo $page_count - $posts_per_page + 1 . ' - ';
    			break;
    		}
    		if($wp_query->found_posts < $page_count) { echo $wp_query->found_posts; }
    		else { echo $page_count; }
    		?> of
    		<?php echo $wp_query->found_posts; ?> results</h4>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    		</div>
    
    		<br />
    		<br />
    
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div <?php post_class() ?>>
    				<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    				<small><?php the_time('l, F jS, Y') ?></small>
    
    				<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    			</div>
    
    		<?php endwhile; ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2 class="center">No posts found. Try a different search?</h2>
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>
    
    	</div>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Displays the result count, works with paging, and adjusts the “Showing results” numbers to match the page..

    Don’t use showposts in the query though, because it’s up to the search to determine “how many” posts (total) will return in the result.. all you need do is adjust the “posts per page” parameter to suit how many you want on each given page.

    Cool. That works. Might have to grab that and integrate it into my search page and then not use the plugins Custom Query String and Results Count, as I only use CQS for search anyway…. Thanks

    Here’s the current version i’ve been playing with, i’ve included the code i’ve used to generate the search form inside comments toward the bottom.

    https://wordpress.pastebin.com/f24b1ee9e

    Few quirks, and a little inline CSS (i’m still playing with it), but it might be of use to someone..

    randyhoyt

    (@randyhoyt)

    I think this is what you had in mind:
    lohmantrading.com/Fourced/2009/08/modifying-the-posts-per-page-query-in-wordpress/

    It allows you change only a single parameter for the query, leaving everything else untouched. I am using this on a blog where the main pages only show 6 posts but the search results page shows 20 posts.

Viewing 9 replies - 16 through 24 (of 24 total)
  • The topic ‘Have more search results show up’ is closed to new replies.