5

I am very new to WordPress, I have very little knowledge with PHP. I read about PODS and I know how to create one and use pages / templates to display data.

The issue I am havingis, the PODS I was creating use static data entered via the WP dashboard, what I want is to read data from a database, I am using MySql (same DB that wordpress is using). is there a way to use PODS and read the data from the DB, or wordpress has a better way to handle data coming from the DB ?

Thanks

Adrian Heine
  • 4,051
  • 2
  • 30
  • 43
Pacman
  • 2,183
  • 6
  • 39
  • 70

3 Answers3

5

You should Look into the $wpdb variable (and class)
http://codex.wordpress.org/Class_Reference/wpdb

Do remember to declare it a global:

<?php global $wpdb; ?>

I am however not sure what you want.
I advise staying close to wordpress.
If you want to create your own custom post types without using code use moretypes

janw
  • 6,672
  • 6
  • 26
  • 45
4

Usual way to read from database in WordPress is the following:

  1. get global variable $wpdb

    global $wpdb
  2. prepare the output and SQL command

    $output = "";
    $sql = "SELECT ".$wpdb->prefix."posts.post_title,
    ".$wpdb->prefix."posts.post_name FROM ".
    $wpdb->prefix."posts WHERE ".$wpdb->prefix.
    "posts.post_status='publish' AND ".$wpdb->prefix.
    "posts.post_parent=0 AND ".$wpdb->prefix.
    "posts.post_type='sometype'";
  3. method get_results() retrieves values from db

    $posts = $wpdb->get_results($sql);
    $output .= '';
    foreach ($posts as $post) {
    $output .= '
  4. post_name). '">'.strip_tags($post->post_title).'
  5. '; } $output .= ''; echo $output;
inigomedina
  • 1,791
  • 14
  • 21
0

Wordpress CSM has a very good class to work with db, i think the better bet on this is learn how db connects and get data from mysql

Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116