• Resolved Jean LeSheep

    (@cyarema)


    It doesn’t seem that the plugin is indexing my media library attachment pages for images. I’m also using the Enhanced Media Library plugin to add categories to my images in the media library. I have everything checked for indexing and also rebuilt the index. I’ve added a title and description to the image, but when I search a term in the title or description it doesn’t appear in the results. Does this plugin search image files?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Yes, Relevanssi can index attachment pages. Have you checked the “attachment” post type?

    If you have and you’re still not seeing images in search results, then it’s possible your theme is restricting the post types in the search.

    If you search for something that should return an image in the results and then add &post_types=attachment to the end of the search results page URL, does that make the image show up?

    Thread Starter Jean LeSheep

    (@cyarema)

    It did work when i added &post_type=attachment. I couldn’t find anything in my theme related to attachment search, but I did find this snippet for anyone else that might need it:

    function my_attachments_search( $query ) {
     if ( !is_search() ) 
        return $query; 		
     
      $post_types = $query->get( 'post_type' );
      if ( ! $post_types || 'post' == $post_types )
        $post_types = array( 'post', 'attachment' );
     
      if ( is_array( $post_types ) ) 
        $post_types[] = 'attachment';
     
      $query->set( 'post_type', $post_types );
      return $query;
    }
    // hook our function to the filter
    add_filter( 'pre_get_posts', 'my_attachments_search' );
    Plugin Author Mikko Saari

    (@msaari)

    Here’s a more compact version of the function, just for setting the search post types to post and attachment.

    add_filter( 'relevanssi_modify_wp_query', 'rlv_post_types' );
    function rlv_post_types( $query ) {
        $query->set( 'post_type', array( 'post', 'attachment' );
        return $query;
    }
    Thread Starter Jean LeSheep

    (@cyarema)

    Is there something slightly off since I got this message:
    Parse error: syntax error, unexpected ‘;’ in /home3/dtphost/public_html/example/blog/wp-content/themes/theme/functions.php on line 48

    Plugin Author Mikko Saari

    (@msaari)

    Yeah, it’s missing a closing parentheses:

    add_filter( 'relevanssi_modify_wp_query', 'rlv_post_types' );
    function rlv_post_types( $query ) {
        $query->set( 'post_type', array( 'post', 'attachment' ) );
        return $query;
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Index Attachment Pages’ is closed to new replies.