Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress Help: Search not working using a custom query on homepage

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #35706
    vnvillar
    Participant

    Hi guys,

    I have a site I’m currently working on but when I tried doing a search it didn’t worked. Here’s the code of from the index.php file:



    -65, 'paged' => get_query_var('paged') ) ); ?>






    When I tried removing this line -65, ‘paged’ => get_query_var(‘paged’) ) ); ?> my search worked but my pagination would be affected too.

    Is there anything I need to do? I hope someone can help

    Thanks guys! :)

    Val

    #93133
    TheDoc
    Member

    Instead of using index.php, why don’t you create a new template called search.php?

    #93162
    vnvillar
    Participant

    Hi Doc,

    My search area is located in the sidebar.php

    Can you tell me why I should create a search.php file?

    Thanks!

    Val

    #93183
    TheDoc
    Member

    The search.php file will be your search results page. Here’s a loop for a search results page that I recently did:

    Search Results





    $searchquery = trim( get_search_query() );
    if ( !empty($searchquery) ) {
    printf( __( '

    Search Results for: %s', 'twentyeleven' ), '' . get_search_query() . '

    ' );
    } else {
    echo "

    Oops - you didn't specify a search term

    ";

    $searchquery = trim( get_search_query() ); echo "

    Please try searching again by entering one or two words on the subject that you are trying to find more information on.

    ";

    } ?>




    if ( !empty($searchquery) ) { ?>

    ">








    $searchquery = trim( get_search_query() );
    if ( !empty($searchquery) ) {
    wp_pagenavi();
    }
    ?>



    Nothing Found



    Sorry, but nothing matched your search criteria. Please try again with some different keywords.



    If you're still having trouble, try using some of the quicklinks below:





    #93452
    vnvillar
    Participant

    Thanks Doc! :)

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.