• Resolved thefoodaholic

    (@thefoodaholic)


    Hi Guys,

    Hopefully you can help as my site is currently looking awfull when I use the search function!

    If you go to my site https://www.thefoodaholic.co.uk, scroll down to the search function on the right and search for example the word ‘gigi’.

    Instead of bringing up just the published posts its also bringing up random images and default logo urls showing image dimensions etc… Out of the three results it brings up the official post is the far right.

    What’s going on! ??

Viewing 12 replies - 1 through 12 (of 12 total)
  • Random images?
    Those are attachments which matches “gigi”
    Default logo? The one you uploaded as default thumbnail?
    The url showing image dimensions and so on, same thing as above, normal for attachments.
    It has always worked this way, maybe you never noticed it, but Customizr by default includes attachments in the search results.
    The only real “issue” here is that is getting the default image instead of the attachment itself as thumbnail. This is weird.
    To exclude attachments in search, you have to add this to your child-theme functions.php

    // Exclude images from search results - Customizr
    add_action('wp_loaded', 'exclude_images_from_search_results', 100);
    function exclude_images_from_search_results(){
        if ( class_exists('TC_post_list') && method_exists('TC_post_list', 'tc_include_attachments_in_search') )
            remove_filter( 'pre_get_posts', array(TC_post_list::$instance,'tc_include_attachments_in_search') );
    }

    which is an updated version of this old snippet

    Hope this helps.

    Thread Starter thefoodaholic

    (@thefoodaholic)

    Hi thanks!

    I don’t have a child-theme but instead am using the custom CSS. I’ve made very few amendments to my CSS.

    I added the code you gave me above to me custom CSS editor instead but it did not work?

    Thread Starter thefoodaholic

    (@thefoodaholic)

    I tried the codes here from this snippet too: but they did not work either.

    As I review restaurants I just want to find away that when someone searches either a name, area etc all that comes up are the posts and no image links/attachments.

    Thanks again!

    Sorry but:

    To exclude attachments in search, you have to add this to your child-theme functions.php

    never said you could chose where ?? (obviously php code doesn’t work in css box (or css files) )
    Make a child theme and put it in its functions.php or, put it in your parent-theme functions.php but at your own risk, ’cause it will be deleted when you update the theme ??

    Anyway creating a child theme it’s simple:
    https://doc.themesandco.com/customizr/creating-child-theme-customizr/

    You will inherit all your customizations you made in Appearance -> Customize.
    The only thing you have to set again is the menu, and the widgets.
    But not re-build them, just set the menu you created as main theme menu again, and put the widgets in their widgets areas.

    p.s.
    as I told you, the code I gave you is the updated version of the codes at that link ( updated version of the first one, which doesn’t work with the latest customizr versions ).
    But of course no php code will never work if you put it in your custom css box.

    Thread Starter thefoodaholic

    (@thefoodaholic)

    done, done and done. You are a GOD!

    Thankyou so much!

    Thread Starter thefoodaholic

    (@thefoodaholic)

    Actually I am back!! Sorry. So that worked getting rid of images, but it’s still bringing up posts which have the word ‘gigi’ or ‘mayfair’ in the posts content. Is there a way I can set the search function so that it uses the the categories as a base to what the search results bring up?

    Thanks I tried to tell HIM I’m so, but he got angry ??
    Glad you solved!

    Thread Starter thefoodaholic

    (@thefoodaholic)

    and the post title. Or is this asking to much from the search function. Ideally i’d want the search function to bring up results usuing post titles and categories. Sorry i did not make this very clear. A little new to it all.

    Mmm but it shows post titles, though not categories..
    did you disabled categories showing in the post metas?

    Thread Starter thefoodaholic

    (@thefoodaholic)

    Not sure what you mean, sorry…

    Maybe this makes sense:

    So if I search ‘Mayfair’ it brings up all the mayfair located restaurants, but also others such as (https://www.thefoodaholic.co.uk/2014/12/review-zaika-kensington-high-street.html). This resturant is located in Notting Hill but has the word ‘Mayfair’ in the body of the posts text so I assume it’s getting it from there. I make sure I categorise every post by location as I use that to create my menu selection tabs (by area). So if you mean disable the post metas wouldn’t that ruin my menus?

    Ahh I see what you mean,
    you would like to restrict the search on the post titles and categories, basically you don’t want the search function searching in the content of the article, right?
    This is about how wordpress searches ??
    Googling for it.. this looks like working fine to limit the search just to post title, not to categories though

    https://wpsnipp.com/index.php/functions-php/limit-search-to-post-titles-only/

    But as suggested in that page you can try a plugin to configure your search : https://www.ads-software.com/plugins/search-everything/

    I haven’t tried it.

    About post metas, I was just talking about displaying the category in the post metas below the article title ??

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘{Customzr} Search Function going crazy!’ is closed to new replies.