Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
WordPress Plugin Development

Preventing SQL Injection

Prevent SQL injection with $wpdb->prepare and trusted allowlists for SQL identifiers.

Preventing SQL Injection — a practical guide to WordPress SQL injection with clear examples you can reuse in real projects.

WordPress Plugin Development Series (73/95). Prefer one article? Read the complete WordPress plugin development tutorial.

Short description

Never concatenate unsanitized user input into SQL. Prepare values; allowlist column/orderby names.

Safe query

$rows = $wpdb->get_results(
    $wpdb->prepare("SELECT * FROM {$wpdb->prefix}acme_items WHERE title LIKE %s", '%' . $wpdb->esc_like($q) . '%')
);

Leave a reply

Your email address will not be published. Required fields are marked *