easy-digital-downloads
easy-digital-downloads copied to clipboard
Look into updating edd_ajax_download_search to search titles only
Enhancement Request
Explain your enhancement (please be detailed)
A customer is reporting that the edd_ajax_download_search
function is returning unexpected, and too many, results. I think the primary reason for this is that it is using the standard search parameter for the core WP function get_posts
and that kind of query searches not only the title (which is really what would be most useful and appropriate for the product dropdown), but also the excerpt and content. Here's a stripped down example of the query:
SELECT wp_posts.ID
FROM wp_posts
WHERE 1=1
AND (((wp_posts.post_title LIKE '%licensed%')
OR (wp_posts.post_excerpt LIKE '%licensed%')
OR (wp_posts.post_content LIKE '%licensed%')))
AND wp_posts.post_type = 'download'
AND ((wp_posts.post_status = 'publish'))
ORDER BY wp_posts.post_date DESC
LIMIT 0, 5
Justification or use case
I think if the product dropdown searched only the titles, it would give more expected results for users, who are probably really just searching by title in this context, and it should be faster.
That's it! A title search would be very useful 👍 Thanks Matthias
@robincornett, thanks for posting this one as this is super frustrating on sites with lots of products :)
I might be being overly cautious here, but I would use $wpdb->esc_like
in that where filter for safety.
Not this exact code, but something like this:
$formatted_frag = '%' . $wpdb->esc_like( strtolower( trim( $frag ) ) ) . '%';
$where_frags[] = $wpdb->prepare( "{$key} LIKE %s", $formatted_frag );