Skip to main content
1 of 3
Sally CJ
  • 39.9k
  • 2
  • 26
  • 48

If you want to retrieve just a single value, you should use $wpdb->get_var():

$post_id = $wpdb->get_var( $prepare_query );

But you can also use $wpdb->get_col(). Just remember — on success — it returns an array and not a string:

$post_ids = $wpdb->get_col( $prepare_query );
$post_id = $post_ids[0]; // simplified and assuming this is set
Sally CJ
  • 39.9k
  • 2
  • 26
  • 48