Can you enable live search pull up pages in addition to articles?

This support request was posted in Flatbase by kurtal

Request ID #7080 Resolved
  • Hi Juan,

    I want live search to come up with pages and articles. Right now, it only shows articles, but if you hit enter and look at the search results page, it includes pages.

    Is there a way to enable live search to include pages?

    Best,
    Kurt

    Juanfra Aldasoro

    Hi Kurt,

    I hope you are doing well.

    We have thought of that and we’ve included a filter so anybody who wants to include another post type/page to the live search can do it with a simple function.

    You can check our snippet here: https://gist.github.com/juanfra/72c242ec4c4b35263055

    You can include that into your theme functions.php file and replace post with page and you’ll start seeing the pages within the live search.

    Best,
    Juan.

    Hey Juan,

    Thanks for your quick response. So I accidentally added a ‘}’ to the end of the snippet you sent over and crashed my site (yay! jumpkick woo!).

    Error message:
    Parse error: syntax error, unexpected ‘}’ in C:\Users\farmeron\kb.farmeron.com\wwwroot\wp-content\themes\flatbase\functions.php on line 37

    I need to use FTP to fix my mistake. Do you have a copy of the theme functions.php file you can send me so that I can go in and replace the existing file?

    Thanks again for your help!

    Juanfra Aldasoro

    Hi,

    Thanks for the follow up.

    Sure, you can get a copy of the file here: https://cloudup.com/cwg9ZBR8Z5b

    Remember that you can always re-download the theme and get the original files.

    Best,
    Juan.

    Thank you, Juan!

    Hey Juan,

    Hopefully just one more question, I received the following error message in the live search after adding the code to include pages:

    Warning: Wrong parameter count for next() in C:\Users\farmeron\kb.farmeron.com\wwwroot\wp-content\themes\flatbase\search.php on line 36

    I removed next() and that seemed to fix the problem, but I wanted to know what you think is best practice in this situation.

    Thanks in advance for your support!

    Juanfra Aldasoro

    Hi,

    Thank you for the follow up. Would you please copy the exact code that you have added to the functions.php file?

    Thank you,
    Juan.

    function nice_livesearch_add_post_type( $post_types ){

    $post_types[] = ‘page’;

    return $post_types;
    }

    add_filter( ‘nice_live_search_post_type’, ‘nice_livesearch_add_post_type’ );

    Juanfra Aldasoro

    Hi,

    Thank you for the follow up.

    Well, the problem has to do exactly with what you’ve pointed out. The next(); function. That’s because we weren’t looking to include pages in the live search at first.

    So, you can keep that modified version of search.php and we’ll fix it for the upcoming version. Thanks for the catch.

    Best,
    Juan.

    Great, I’ll go ahead and remove the next(); function then.

    Thanks for your help.

    Juanfra Aldasoro

    No problem 🙂 My pleasure.

    Have a nice day,
    Juan.

Viewing 11 posts - 1 through 11 (of 11 total)

This topic is marked as resolved

Only the topic author can re-open this thread.

Login to your Account

Welcome back! Please log in to your account by filling the fields below:

Forgot?

Not a member? Create a free account.

Create a Free Account

You're 27 seconds away from some awesome WordPress free stuff, benefits and more. Create a free account and have access to our free products, benefits and more!

Already have an account? Log in
Secure Server