I have created the below function in wordpress in my themes functions.php file. I want to call this function in my theme template and have the portion of the foreach portion echo’d in my theme template. How exactly would I do this? I presume I have to return somthing from the function but I am not sure how to set this up. Your help is much appreciated.
function geography_navigation($type, $field1, $field2, $field3, $field4, $field5) {
global $wpdb;
$results = $wpdb->get_results("SELECT DISTINCT wp_eva_geography.$field1, wp_eva_geography.$field2
FROM wp_eva_geography
WHERE wp_eva_geography.$field3='$type' AND wp_eva_geography.$field4='$geo_no_dash';");
echo "<ul>";
foreach($results as $geography){
echo "<li> <a href='/$type/$field5/{$geography->$field2}/'>{$geography->$field1}</a></li>";
}
echo "</ul>";
}
Set the output into a variable and return it like so:
Please note I have note tested this but believe it should work… Let me know!