search through post-type attachments titles

I have a page where I show all the attachments of a page in a table which has id=10.

I have hundreds of attachments and I would like to implement an AJAX search form that uses the title of attachment as key for search.

Actually the problem is not in implementing the AJAX call, but the query that returns the attachments list.

3 Answers
3

You should try applying the s(search) as parameter for your custom query.

See this example here:

$query = new WP_Query( 's=keyword' );

and you can then apply normal loop to iterate through your results. This also performs string match same as like operator %keyword% you mentioned in comment for @Ravs’ answer.

Refer documentation here.

Leave a Comment