Forums

How to make the search function include post_type = "attachment"? (10 posts)

  1. dcjob
    Member
    Posted 2 years ago #

    I uploaded some attachments with title and description. How to make the search function on front page to search these attachments?

  2. esmi
    Theme Diva & Mod
    Posted 2 years ago #

  3. dcjob
    Member
    Posted 2 years ago #

    I tried "search-everything", it does not work for search the description of the files in Media. I think it need to hack the codes of WP, make the searching include not only post_type="page" and "post", but also "attachment". Who knows how to do it? Thanks.

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    In order to query for attachments you'd need to set post_status to inherit or any... (using "any", drafts etc.. will show up)..

  5. dcjob
    Member
    Posted 2 years ago #

    How to change the post_status by default? I want the post_status will be "any" when a user adds a file into Media. Thank you!

  6. Mark / t31os
    Moderator
    Posted 2 years ago #

    I think you're missing the point, if you query for any, you'll also end up with Drafts and Revisions, etc... in the results..

  7. dcjob
    Member
    Posted 2 years ago #

    How to do it? In "Search" function, no options. Or I need add an entry in config file? Thank you!

  8. web00132
    Member
    Posted 2 years ago #

    I would also like to be able to include the attachment description when searching, this doesn't seem doable with the 'Search Everything' plugin. Don't get that stuff about setting something to 'any', what do you mean?

  9. Mark / t31os
    Moderator
    Posted 2 years ago #

    The search query, by default is set to post, if you add a query arg into the query posts line of your search.php, you can do any number of things..

    if(!$wp_query) global $wp_query;
    $args = array(
    'post_type' => 'any',
    'category' => 3,
    'author' => 1
    );
    query_posts( array_merge( $args , $wp_query->query ) );

    There's a few example args in the above... ;)

    Again, i'll repeat, if you use "any" you'll also get Drafts and Revisions, amongst other things in the result set.

    Attachments, should you want to query for them specifically, have a post_type of inherit. The actual post type is inheritted from the attachments parent, which is usally the post it has been attached/inserted into, if one exists...

  10. alanchrishughes
    Member
    Posted 1 year ago #

    Where would you enter that query info, Mark? The twentyten theme only has a search results page file, not search form file. Or are you saying you would have to write your own custom search box, which would really be best because you wouldn't want every every search box on the entire site to return the some custom post type results.

Topic Closed

This topic has been closed to new replies.

About this Topic