skip to Main Content

WordPress Code Snippets


Running a SELECT Query with Placeholders -Prevent SQL injection

This snippet demonstrates how to safely run SQL queries using placeholders to prevent SQL injection.

global $wpdb;

$post_status = 'publish';
$query = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}posts WHERE post_status = %s", $post_status);
$results = $wpdb->get_results($query);

foreach ($results as $post) {
    echo $post->post_title . "<br>";
}


I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Best WordPress Hosting
Back To Top
Search