BuddyDev

Search

Replies

  • 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/

  • 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();

  • 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' );
  • Participant
    Level: Initiated
    Posts: 6
    Fah Q on #18478

    Yes this seems to have worked.

    However, if you manually rearrange items, that code is ignored. I suppose that is how it should work.

  • Participant
    Level: Initiated
    Posts: 6
    Fah Q on #18465
    function buddydev_modify_media_order( $args ) {
    
    $args['order'] = 'ASC';
    
    return $args;
    }
    add_filter( 'mpp_main_media_query_args', 'buddydev_modify_media_order' );

    Changing ASC to DESC doesn’t seem to change the order

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

    Unfortunately, that code didn’t work.

    I am relying on the manual re-ordering at the moment, but would still like to know if can sort the documents alphabetically by default