$wpdb->get_results() give error inside another get_results

i have code i use two $wpdb->get_results()
first i run first query and then i use foreach but i want to run loop again $wpdb->get_results() but it does not work give me error 500

global $wpdb;

   $sql = "select * FROM {$wpdb->prefix}posts WHERE `post_type` = 'property' and post_title != 'Auto Draft' and post_status != 'trash' ORDER BY post_date DESC";

$get = $wpdb->get_results( $sql );
            foreach($get as $rows){
                $row = get_object_vars($rows);
                     echo '</br>';
                    $sqla = "SELECT pm.meta_key,pm.meta_value,p.post_title FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts p ON pm.post_id = p.ID WHERE pm.post_id = ".$row['ID'];
                    $get2 = $wpdb->get_results( $sqla );
                    // foreach ($get2 as $meta_query) {
                    //  $meta_querys = get_object_vars($meta_query);
                    //  print_r($meta_querys);
                        // }



Read more here: $wpdb->get_results() give error inside another get_results

Leave a Reply

Your email address will not be published. Required fields are marked *