WordPress.org

Ready to get started?Download WordPress

Forums

Customizr
[resolved] Search results disappoint (8 posts)

  1. chappie
    Member
    Posted 4 months ago #

    When I started playing with my shiny new Search form, I got a nasty shock in that the search results were sub-optimal, to say the least. My (offline) site is mostly static pages and it seems WP search function is mostly post-oriented -- although it does return every image title on the site.

    I now see - here - that there are acknowledged shortcomings in the WP search function so this is really off-topic for this forum, hence I've marked it Resolved.

    But if anyone here knows how to a) force the engine to search in static pages; and b) stop it returning image titles which are anyway invisible to visitors, I would be jolly grateful to know the answer. Perhaps I get the image titles returned because I am logged in as Admin and they wouldn't be returned in a live search by a vsitor?

  2. Manu-PB
    Member
    Posted 4 months ago #

    I personally use and strongly recommend relevanssi which is of very high power, also for static pages.

  3. rdellconsulting
    Member
    Posted 4 months ago #

    Isn't the answer within your linked article? Use a different solution?

  4. chappie
    Member
    Posted 4 months ago #

    @Manu-PB - thanks for the rec: I will take a look at it.

    @rdellconsulting - Hi Dave: I hope so. The article looks quite credible. But I wanted to see if anyone here had solved the problem to their satisfaction...which would also rule out any plugin conflicts.

  5. ElectricFeet
    Member
    Posted 4 months ago #

    Hi Chappie. I too find it annoying that a search brings up all your images, one by one. It's because of my obsession with captioning (which makes the site highly google-friendly, BTW, so it's a Good Thing).

    You can remove images from the search with the following code in functions.php:

    // Exclude attachments (images) post type from searches
    add_action( 'init', 'exclude_images_from_search_results' );
    function exclude_images_from_search_results() {
    	global $wp_post_types;
    
    	$wp_post_types['attachment']->exclude_from_search = true;
    }
  6. d4z_c0nf
    Member
    Posted 4 months ago #

    @ElectricFeet
    Mmm just remembered reading your answer, that I did something of the sort some weeks ago :D. I looked in customizr/parts/class-content-post_list.php
    and then I added this to my child-theme functions.php:

    /* exclude attachments in search */
    add_action('init', function(){
    	remove_filter( 'pre_get_posts', array(TC_post_list::$instance, 'tc_include_attachments_in_search') );
    });
  7. ElectricFeet
    Member
    Posted 4 months ago #

    Ah, interesting. I saw that function but couldn't figure out how to use it :-)

    Your method wins on having 50% fewer lines of code. Mine wins on being theme-independent. So we're quits this time :-)

    Coding really is creative, isn't it? :-)

  8. d4z_c0nf
    Member
    Posted 4 months ago #

    Yep :D

Reply

You must log in to post.

About this Theme

About this Topic