php wpdb foreach

Solutions on MaxInterview for php wpdb foreach by the best coders in the world

showing results for - "php wpdb foreach"
Emely
27 Mar 2020
1get_header();
2function get_records()
3{
4	//$con=connectsql();
5	$records=$wpdb->query("SELECT * FROM $wpdb->posts WHERE post_type = 'elements' AND post_status = 'publish'");
6	$all=array();
7	while($data=$records->fetch_assoc())
8	{
9		$all[]=$data;
10	}
11	return $all;
12}
Samia
30 Nov 2020
1
2	$records=$wpdb->query("SELECT * FROM $wpdb->posts WHERE post_type = 'elements' AND post_status = 'publish'");
3
4	while($data=$records->fetch_assoc())
5	{
6		print_r($data);
7	}
8	
9}