SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    choose search results displayed per page

    I want to offer the option of allowing someone to choose the number of search results displayed on a page - similar to the function on this site: http://wordpress.stackexchange.com/q...tom-post-types e.g. 15, 30, 50 per page. I am using the Relevanssi search plugin but didn't find an option. Any help appreciated.

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    9 Thread(s)
    posts_per_page is the way to go.
    Just add this to your functions.php file:

    Code PHP:
    add_filter('post_limits', 'postsperpage');
    function postsperpage($limits) {
    	if (is_search()) {
    		global $wp_query;
    		$wp_query->query_vars['posts_per_page'] = 10;
    	}
    	return $limits;
    }

    And adjust the value (10) to whatever you want.
    This will work with Premium version 1.4.4 and upwards, as well as free 2.9.2. and upwards.

    Ref.: http://www.relevanssi.com/knowledge-...osts-per-page/

  3. #3
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    9 Thread(s)
    Hi,

    Just been playing around with this.
    If you want to do it like the stackexchange site, that the user can select how many search results they wish to be displayed on a page, you could add a drop-down menu (or similar) to the WordPress search form.
    The value that the user selects can then be picked up in the $_GET superglobal in functions.php
    You could then write:
    Code PHP:
    $wp_query->query_vars['posts_per_page'] = $_GET["delimit"];
    where delimit is the name you gave your drop-down.

  4. #4
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Pullo, thanks for the help. I'll try out your suggestion.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •