• dcjob

    (@dcjob)


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

Viewing 9 replies - 1 through 9 (of 9 total)
  • esmi

    (@esmi)

    Thread Starter dcjob

    (@dcjob)

    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.

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

    Thread Starter dcjob

    (@dcjob)

    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!

    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..

    Thread Starter dcjob

    (@dcjob)

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

    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?

    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…

    alanchrishughes

    (@alanchrishughes)

    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.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to make the search function include post_type = “attachment”?’ is closed to new replies.