• Resolved jasonkadlec

    (@jasonkadlec)


    I like the default of 7 results returned… but I do want to be able to allow users to click to the .com/?s=search-query page to view all results.

    I can use some javascript to grab whatever they typed into search field, and then use that to set the href of the link… but hoping there would be maybe something PHP based that I could hook onto and just echo in the search-results.php template that I’ve copied into the theme.

    Thanks!

    J

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jasonkadlec

    (@jasonkadlec)

    Update ( not solved yet) — it looks like search-results.php should just work like whatever would be used on search.php in a default theme… however

    the_search_query();

    as well as

    get_search_query()

    are both NULL….

    Maybe javascript really is the way to go since once the search is open…the user can keep typing which keeps interacting with the search, so the “view all” link should be keeping track of/live updating itself to whatever is actually getting typed in… hmmm.

    Thread Starter jasonkadlec

    (@jasonkadlec)

    Ah so easy!

    I’m using a search form, and so I updated the button to say “view all results” – when clicked, it submits the form / page redirects to the .com/?search=etc-etc

    No need to put a link at the bottom, just use a button next to the input field which will submit the form.

    Plugin Contributor Jon Christopher

    (@jchristopher)

    Hi there! Just to follow up on the original inquiry:

    You’re right, get_search_query() doesn’t work here because the plugin is using a different variable, you can use this instead:

    $search_query = isset( $_POST['swpquery'] ) ? sanitize_text_field( $_POST['swpquery'] ) : '';

    From there you can follow the results template customization guide to output a link to

    $full_results_link = add_query_arg(
      array(
        's' => $search_query
      ),
      site_url()
    );
    echo '<a href="';
    echo esc_url( $full_results_link );
    echo '">All results</a>';

    and that should do it!

    • This reply was modified 7 years, 7 months ago by Jon Christopher. Reason: Formatting to prevent horizontal scroll
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add link to view all results?’ is closed to new replies.