BuddyDev

Search

[Resolved] Search Media titles

  • Participant
    Level: Initiated
    Posts: 6
    Fah Q on #18493

    I am unable to search media inside galleries.

    The default search only searches the gallery titles but not the media inside.

    I have tried:

    https://wordpress.org/plugins/buddypress-global-search/

    https://wordpress.org/plugins/eonet-live-search/

    But neither displays results for media items inside galleries.

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #18494

    Hi Fah,
    Do they support attachment post type? If yes, Please enable it and you can search for media titles.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 6
    Fah Q on #18496

    No, none of those plugins support attachment post type.

    I have tried using the wordpress search widget and added this function to search attachments but attachments are still not searched or displayed:

    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( 'page','post', 'attachment','mpp-gallery' );
     
      if ( is_array( $post_types ) ) 
        $post_types[] = 'attachment';
     
      $query->set( 'post_type', $post_types );
      return $query;
    }
    add_filter( 'pre_get_posts', 'my_attachments_search' );
  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #18497

    I will not suggest doing above. It wont work for attachment.

    The post status for attachment is set to ‘inherit’ while the above only searches for published posts.

    I do not suggest changing the post status in wp main query. Instead, I will suggest either asking the search plugin developers to support attachment or create a specific search page for attachment and setting the status to include ‘inherit’ too.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 6
    Fah Q on #18498

    This function worked with default wordpress search widget:

    function attachment_search( $query ) {
        if ( $query->is_search ) {
           $query->set( 'post_type', array( 'post', 'attachment','mpp-gallery' ) );
           $query->set( 'post_status', array( 'publish', 'inherit' ) );
        }
     
       return $query;
    }
    
    add_filter( 'pre_get_posts', 'attachment_search' );

    Gallery items are now displayed in search results. However, how can I get this to work with the default Mediapress search?

    mpp_directory_gallery_search_form();

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #18505

    Hi Fah,
    We do not support media search on the gallery directory page. Changing query will most probaly have no effect or will not have intended effect as we load galleries loop there and not for media.

    For now, you may implement a custom search page using shortcode(to list searched media) or a completely custom loop of your own.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 6
    Fah Q on #18513

    I also found this plugin which has search capability for ‘attachment’ post types

    https://wordpress.org/plugins/search-everything/

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #18521

    Thank you for linking to the plugin and marking it resolved.

    Regards
    Brajesh

The topic ‘ [Resolved] Search Media titles’ is closed to new replies.

This topic is: resolved