• Resolved axgalache2

    (@axgalache2)


    Hello there,
    When creating a post, you can add attachment or featured photo to the post.
    When selecting a photo from existing media library, there is a search box:
    https://i.imgur.com/BiSFayw.png
    I would like to know which fields does this input searches by. As far as I investigated, it searches photos by title and/or description. Is this correct? Does it filter photos/attachments by other fields?

    Thank you in advance 🙂

    • This topic was modified 3 years, 4 months ago by axgalache2. Reason: typo in title
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,

    this is the function that queries the search for the media, it seems to search for

    https://developer.wordpress.org/reference/functions/wp_ajax_query_attachments/

    It takes all these things and searches for your query in there, some things in there are probably not interesting to you but I think the labels are what you are looking for:

    stdClass Object ( 
    [hierarchical] => 
    [update_count_callback] =>  
    [rewrite] => 
    [query_var] => 
    [public] => 
    [show_ui] => 
    [show_tagcloud] => 
    [_builtin] => 
    [labels] => stdClass Object ( 
    	[name] =>  
    	[singular_name] =>
    	[search_items] => 
    	[popular_items] => 
    	[all_items] => 
    	[parent_item] => 
    	[parent_item_colon] =>  
    	[edit_item] => 
    	[view_item] =>  
    	[update_item] => 
    	[add_new_item] => 
    	[new_item_name] => 
    	[separate_items_with_commas] => 
    	[add_or_remove_items] => 
    	[choose_from_most_used] => 
    	[menu_name] =>  
    	[name_admin_bar] =>  ) 
    [show_in_nav_menus] => 
    [cap] => stdClass Object ( 
    	[manage_terms] =>  
    	[edit_terms] =>  
    	[delete_terms] =>  
    	[assign_terms] =>  ) 
    [name] =>  
    [object_type] => Array () 
    [label]  )
    • This reply was modified 3 years, 4 months ago by Benedikt Ledl.
    Moderator bcworkz

    (@bcworkz)

    The relevant WHERE clause from searching for media items with “test” looks like this:

    (((wp_posts.post_title LIKE '%test%')
    OR (wp_posts.post_excerpt LIKE '%test%')
    OR (wp_posts.post_content LIKE '%test%')
    OR (sq1.meta_value LIKE '%test%')))

    If the search term is not in one of those items, the media item will not be found. Note that sq1.meta_value could possibly cover a lot of information.

    So if I understand this correctly, the search function in the Media Library does not search any of the document/image fields like alt text, caption or description?

    Thread Starter axgalache2

    (@axgalache2)

    The field ‘post_content’ noted in the comment above yours corresponds to the ‘description’ field of the document/image, and ‘post_excerpt’ corresponds to caption field

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Media search: What fields does it searches by’ is closed to new replies.