Template File Ignoring WPDB Queries
-
I apologize in advance if this is in the wrong forum, I was torn on this or Miscellaneous.
I have been browsing these forums and Google for hours and haven’t found a solution to my problem yet.
I have never really used the $wpdb class very much, so my problem may relate to me being a noob.
My blog, hosted on my own server, relates to video games and I am trying to create a Game of the Day feature using a simple table that I created in the database. I named the table thegameniac_gotd (thegameniac being my defined table_prefix)
Now, as part of my template, I have created and defined a new page template called gotd.php, which loads up fine and works great. The normal functions: the_content() and the_title() are working great, but when I try to call the database, it seems my queries are being completely ignored.
I toyed around with some stuff trying to make sure that the wp-db.php was included etc, but still nothing, it just skips the entire query. I made sure that $wpdb was globalized, but it didn’t seem to care if it was or not, it just did nothing. I tried changing the query, tried get_row, tried just query, still nothing. I even purposely messed up the query (IE typed SEL instead of SELECT) just to see if it would fail, and it just passed right by it. So it is completely ignoring it all together for some reason.
I tried moving the query inside the loop to see if it needed to be there, still nothing. I have looked at examples over and over again and I just can’t see anything wrong with it.
The page in question is here (note that the site really isn’t ready yet, so it has a lot of fake text):
https://www.thegameniac.com/gotd/The code in question is below:
<?php $date = date("Y-m-d"); global $wpdb; $game = $wpdb->get_results("SELECT * FROM $wpdb->gotd WHERE gameDate = '$date' "); $gameID = $game->gameID; $title = $game->gameTitle; $releaseDate = $game->gameReleaseDate; $platforms = $game->gamePlatforms; $description = $game->gameDescription; ?> <div id="gotd"> <h2><?php echo date('F j, Y'); ?></h2> <p><img src="<?php echo WP_CONTENT_URL; ?>/boxart/<? $gameID ?>.jpg" alt="Box art for <?php $title ?>"></p> <table cellpadding="5" cellspacing="0" border="0"> <tr> <th>Title</th> <td><?php echo $title; ?></th> </tr> <tr> <th>Release Date</th> <td><?php echo $releaseDate; ?></td> </tr> <tr> <th>Platforms</th> <td><?php echo $platforms; ?></td> </tr> <tr> <th>Description</th> <td><?php echo $description; ?></td> </tr> </table> </div>
So yeah, I am not sure at all what could be the problem. Is it because it’s in a new template page or what? I mean if the $wpdb class wasn’t included, it would be giving me an error. If the query was messed up, it would give me an error. I am getting nothing but blanks.
Any help anyone could give me would be greatly appreciated.
Thanks!
- The topic ‘Template File Ignoring WPDB Queries’ is closed to new replies.