skip to Main Content

WordPress Code Snippets


Fetching a Single Value from a in WordPress database

Learn how to fetch a single value (e.g., post title) from the database using $wpdb->get_var().

global $wpdb;

$post_id = 1; // Replace with the ID of the post you want
$title = $wpdb->get_var($wpdb->prepare("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = %d", $post_id));

echo "Post title: " . $title;


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