I have just completed debugging a WordPress function. The debugging drove me crazy finding errors in the query. I now see no errors in the execution of the function but the result does not output via the return. The obvious answer is that the queries did not return anything, however the same code worked perfectly despite the errors before I fixed the query syntax. Now that it shows no errors the output fails to show up on the page. Other clues are that I added an echo and the echo appeared on various pages despite the fact that the code should only run on the Profile page. I'm new to php, so I am lost understanding how code can run without captured errors and yet not appear to function. Especially given that while the error log did show errors it actually worked as intended. It is a simple query to find a members membership name by looking first for the membership level (first query) then finding the actual name of the membership (second Query based on the first). The "return $text.$content;" line appears to not fire. Here's the code:
function Welcome($content) {
$welcome = '';
if ( is_page('Profile'))
$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$numb = str_replace('mysite.org/profile/?user_id=', '', $url);
global $wpdb;
$query = $wpdb->prepare ('SELECT `membership_level_id` FROM `mm_user_data` WHERE `wp_user_id` = %d', '$numb');
$idnum= $wpdb->get_var($query);
$query = $wpdb->prepare ('SELECT `name` FROM `mm_membership_levels` WHERE `id` = %d', '$idnum');
$text= $wpdb->get_var($query);
$text="<h3>$text</h3>";
return $text.$content;
}
add_filter('the_content', 'Welcome');