I have a php script that outputs a link element within a list element depending on certain conditions being met, the code is as follows:
global $wpdb;
function currentURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;}
$getUrl = $wpdb->get_results("SELECT option_name,option_value FROM wp_options WHERE option_name = 'siteurl' ");
$url = $geturl->option_value;
$getData = $wpdb->get_results("SELECT post_title,guid FROM wp_posts WHERE post_type = 'page' ");
echo "<ul id=\"mainNavInnerContainer\">";
if(currentURL() == $url){
echo "<li><a href=\"" . $url . "\" id=\"current\">home</a></li>";}
else{ echo "<li><a href=\"" . $url . "\">home</a></li>"; }
The problem I’m having is that when I view the element in source code view in my browser i get the following:
<a href>Home</a>
I’m really confused as to why this is, and was hoping that anyone else would have any idea why.
EDIT
I was able to use a foreach loop to put the value in my $url variable but is this good practice? Because I know that the query in $getUrl will always return one row, but still this method seems pretty error prone. Here is the revised $url variable code:
foreach($getUrl as $urlResult){
$url = $urlResult->option_value;}
error_reporting(E_ALL);add check:
$getUrl = $wpdb->get_results("SELECT option_name,option_value FROM wp_options WHERE option_name = 'siteurl' "); $url = $geturl->option_value; var_dump($url);