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

<?php 
include('wp-config.php');
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);
                     print_r($row['ID']);
                     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 );
                    print_r($get2);
                    // 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


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: