• I am running the below code and getting an internal error, logs show nothing, if i replace echo $discipline; with echo 1; it works. what am i doing wrong? this is for an ajax call back.

    function get_ajax_disciplines(){
    	global $wpdb;
    	$sql = "SELECT DISTINCT meta_value
    			FROM wpau_postmeta wpm
    				INNER JOIN wpau_posts wp
    					ON wp.ID = wpm.post_id
    						AND wp.post_status = 'publish'
    			WHERE wpm.meta_key = 'post_discipline'
    				AND meta_value NOT LIKE 'a:%'
    				AND meta_value NOT LIKE '%|%'
    				AND TRIM(meta_value) != ''
    				AND meta_value IS NOT NULL
    			ORDER BY meta_value ASC";
    	$disciplines = $wpdb->get_results($sql);
    	
    
    	foreach( $disciplines as $discipline){
    		echo $discipline;
    	}
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • What was the actual error?

    also try

    var_dump($discipline)

    I suspect that $disciplines is a wp_error object

    try checking that the error before the loop

    e.g.

    $disciplines = $wpdb->get_results( $sql );
    
    	if ( is_wp_error( $disciplines ) ) {
    		// do something like log it
    		return;
    	}
    
    	foreach ( $disciplines as $discipline ) {
    		echo $discipline;
    	}
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘internal server error processing $wpdb query results’ is closed to new replies.