admin管理员组

文章数量:1129202

I have a custom table in db with a column recommendation of type int(11). Then as one of my custom route handlers I have

  global $wpdb;
  $query = "SELECT recommendation FROM `restaurants`;
  // todo convert "88" -> 88
  $list1 = $wpdb->get_results($query);
  
  return array('open' => $list1);

The data the front end receives is "88" whereas this should be an int.

In some of my code I have a function that maps each $obj in the list with

$obj->recommendation = (int) $obj->recommendation;

But it feels weird that I need to post process in php rather than get the data correctly from the db itself.

What is the 'best' way to achieve my goal?

本文标签: queryCustom API how to return int field