Knowledge Base »

[15 Mar 2010 | No Comment | ]

Introduction to Wordpress Database: wp_comments
Current Version : 2.9.2
Comments made by users on posts, pages or attachments are saved in this table by wordpress.
To insert a comment manually, one can use wp_insert_comment function. The argument is an array, with information related to the comment.
Check wp_insert_comment for more details.
The structure of the table is as follows:

Field
Type
Null
Key
Default
Extra

comment_ID
bigint(20) unsigned

PRI
NULL
auto_increment

comment_post_ID
bigint(20) unsigned

IND
0
FK->wp_posts.ID

comment_author
tinytext

comment_author_email
varchar(100)

comment_author_url
varchar(200)

comment_author_IP
varchar(100)

comment_date
datetime

0000-00-00 00:00:00

comment_date_gmt
datetime

IND & IND Pt2
0000-00-00 00:00:00

comment_content
text

comment_karma
int(11)

0

comment_approved
varchar(20)

IND & Ind Pt1
1

comment_agent
varchar(255)

comment_type
varchar(20)

comment_parent
bigint(20) unsigned

0
FK->wp_comments.ID

user_id
bigint(20) unsigned

0
FK->wp_users.ID

Indexes

Keyname
Type
Cardinality
Field

PRIMARY
PRIMARY
1
comment_ID

comment_approved
INDEX
None
comment_approved

comment_post_ID
INDEX
None
comment_post_ID

comment_approved_date_gmt
INDEX
None
comment_approved
comment_date_gmt

comment_date_gmt
INDEX
None
comment_date_gmt

Knowledge Base »

[12 Mar 2010 | No Comment | ]

Introduction to Wordpress Database: wp_postmeta
Current Version : 2.9.2
Just like wp_options and wp_usermeta, wp_postmeta is used to save post related data. These data are generally called custom fields.
One can add custom field from post editor, as shown below:

For example, I have the inserted version in each post using the custom fields.
The structure of this table is as follows:

Field
Type
Null
Key
Default
Extra

meta_id
bigint(20) unsigned

PRI
NULL
auto_increment

post_id
bigint(20) unsigned

IND
0
FK->wp_posts.ID

meta_key
varchar(255)
YES
IND
NULL

meta_value
longtext
YES

NULL

Indexes

Keyname
Type
Cardinality
Field

PRIMARY
PRIMARY
13
meta_ID

post_id
INDEX
15
post_id

meta_key
INDEX
7
meta_key

In the table, the value is saved with meta_key and post id.
These fields can be handled using various functions like add_post_meta(),update_post_meta(),get_post_custom() etc. Please check this URL for more details:
http://codex.wordpress.org/Custom_Fields

Knowledge Base »

[10 Mar 2010 | No Comment | ]

Introduction to Wordpress Database: wp_users
Current Version : 2.9.2
Wordpress saves the user details in wp_users table. All the major details like user id, user_login, email address, password (In MD5) are saved in this table.
Below mentioned is the structure of this table:

Field
Type
Null
Key
Default
Extra

ID
bigint(20) unsigned

PRI
NULL
auto_increment

user_login
varchar(60)
IND

user_pass
varchar(64)

user_nicename
varchar(50)

IND

user_email
varchar(100)

user_url
varchar(100)

user_registered
datetime

0000-00-00 00:00:00

user_activation_key
varchar(60)

user_status
int(11)

0

display_name
varchar(250)

Indexes

Keyname
Type
Cardinality
Field

PRIMARY
PRIMARY
1
ID

user_login_key
INDEX
None
user_login

user_nicename
INDEX
None
user_nicename

here, password is  MD5 encrypted.
We manually are not supposed to make any entry in this table. However, you can use this function in your template or plugin:
wp_insert_user()
This function requires an array of data to be inserted for the user. Please check more details here …

Knowledge Base »

[10 Mar 2010 | No Comment | ]

Introduction to Wordpress Database: wp_usermeta
Current Version: 2.9.2
In general, wordpress saves many user related data. It is difficult to save them in one column in wp_users. Hence Wordpress saves these data in wp_usermeta table. The structure of this table is mentioned below:

Field
Type
Null
Key
Default
Extra

umeta_id
bigint(20) unsigned

PRI
NULL
auto_increment

user_id
bigint(20) unsigned

‘0′
FK->wp_users.ID

meta_key
varchar(255)
Yes
IND
NULL

meta_value
longtext
Yes
IND
NULL

Indexes

Keyname
Type
Cardinality
Field

PRIMARY
PRIMARY
9
umeta_id

user_id
INDEX
None
user_id

meta_key
INDEX
None
meta_key

In this table, we need to add following details:
user_id -> user_id of the user
meta_key -> a unique key for the user data
meta_value -> the actual data to be saved.
Wordpress provides following functions to manage this table:
get_usermeta($userid, $metakey )
$userid
(integer) (required) The ID of the user …

Knowledge Base »

[2 Mar 2010 | No Comment | ]

Introduction to Wordpress Database: wp_options
Current Version: 2.9.2
Wp_options tables is used to store wordpress’s default settings, standard options etc. The structure of the table is as follows:

Field
Type
NULL
Key
Default
Extra

option_id
bigint(20) unsigned

PRI Pt1
NULL
auto_increment

blog_id
int(11)

PRI Pt2
0

option_name
varchar(64)

PRI Pt3 & IND

option_value
Longtext

Autoload
varchar(20)

Yes

Indexes

Keyname
Type
Cardinality
Field

PRIMARY
PRIMARY
184
option_id
blog_id
option_name

option_name
UNIQUE
184
option_name

This tables is used by wordpress to save  standard options, like blogurl, blog title, description, admin email address, rewrite rules etc.
This table is very useful for plugin and theme developers. A developer can store his own standard options in this table.
How to save data in this …