Posted By

redconservatory on 07/21/11


Tagged

database php table wordpress codex


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

lilumi


Wordpress: retrieve values from a custom table in the Wordpress database


 / Published in: PHP
 

Refer to the following: http://codex.wordpress.org/Class_Reference/wpdb

  1. <?php
  2. /*
  3. Say you created a
  4. TABLE named food
  5. in the wordpress database
  6. WITH THE COLUMNS
  7. id
  8. name
  9. organic YES/NO
  10. */
  11.  
  12. global $wpdb;
  13.  
  14. $query = 'SELECT id, name, organic FROM food';
  15.  
  16. $rows = $wpdb -> get_results($query);
  17.  
  18. foreach ($rows as $key=> $value) {
  19. $id = $value->id;
  20. $name = $value->name;
  21. $organic = value->organic;
  22. ?><p><?php echo $id; ?></p><?php
  23. ?><p><?php echo $name; ?></p><?php
  24. ?><p><?php echo $organic; ?></p><?php
  25. }
  26. ?>

Report this snippet  

You need to login to post a comment.