wpdb get results foreach code example
Example 1: wpdb get results foreach
$results=$wpdb->get_results("SELECT * FROM your_table_name WHERE id LIKE' . $id . ';");
foreach($results as $key => $row) {
// each column in your row will be accessible like this
$my_column = $row->column_name;}
Example 2: $wpdb foreach
$records=$wpdb->query("SELECT * FROM $wpdb->posts WHERE post_type = 'elements' AND post_status = 'publish'");
while($data=$records->fetch_assoc())
{
print_r($data);
}
}