0

Wordpress - I want to use a title condition for displaying info on a page, from a MySQL table "country".
The condition must compare the title with the names in the column "name" and when it match a value than display on the page the text from column "description" from the same row with the matching value. Example : title(USA)=column name (USA) get/fetch column (description) (the description from row USA).
I had tryed a code

<?php
    $page_name = $wp_query->post->post_name;
    query_posts('category_name='. $page_name);
?>
<?php global $wpdb;
$result = $wpdb->get_row ("SELECT name FROM country WHERE parent IN (SELECT parent FROM country WHERE name == '$page_name'"));
if ($result->num_rows == 0) {   
   echo '<div>No matches found</div>'; 
} else {   
    $i = 0;
    while ($row = $result->fetch_row(description)) {
        if ($row["name"] == '1') {
           echo '<div id="description' . $i . '"></div>'; 
        }
       $i++;
    }

  echo $result->description;

}
?>

I have foud hier a code to display the title

<?php echo get_the_title($ID); ?>

and a code to use the title condition

<?php
$title = the_title('', '', false);
if($title == 'conditional post title'){
// your stuff here
}
?>
3
Contributors
2
Replies
42
Views
3 Years
Discussion Span
Last Post by nauticalmac
1

There is a little typo at line 6, the closing parenthesis is after the double quote, so it is outside the query expression. Change it with this:

$wpdb->get_row("SELECT name FROM country WHERE parent IN (SELECT parent FROM country WHERE name == '$page_name')");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.