好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

wordpress 数据库表结构 - WordPress

wordpress 数据库表结构

最近新学做wordpress的主题,由于自己对wp自带的函数不是很熟悉,用起来比较不方便,不如自己写sql查询来的快,于是便小小研究一下wp的数据库.

我用的是wp3.5版本

假如我想输出某一分类($category_id)下除了标题为[图片]的文章,原本想用wp自带函数query_posts实现,在网上看到一种用法是不想输出某篇文章的话,就用query_posts('p=-1,-2'),于是自己查询出所有标题为[图片]的文章的id号,将这些id号用[-]和[,]连接成字符串$str然后处理一下(去掉多余的逗号之类),query_posts('cat='.$category_id.'&p='.$str),可惜,测试结果是失败的,不知道是我的wp版本问题还是其他原因.

最终,还是自己写sql语句,一步到位:

select  *  from  wp_posts,wp _term_relationships,wp_term_taxonomy  where  ID=object_id  and  wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id   and  wp_term_taxonomy.term_id= ".$category_id."   and  post_type= 'post'   and  post_status = 'publish'   and  post_title  not   like   '%国旗%'   and  taxonomy =  'category'   order   by  ID  desc  

这篇文章涉及的表主要有:

wp_posts:存储文章(包括页面、上传文件、修订)

wp_terms:存储每个分类、标签

wp_term_relationships:存储每个文章、链接和对应分类的关系

wp_term_taxonomy:存储每个分类、标签所对应的分类

这几个表中的各个字段的含义:

wp_posts  ID:ID  post_author:对应作者ID  post_date:发布时间  post_date_gmt:发布时间(GMT+0时间)  post_content:正文  post_title:标题  post_excerpt:摘录  post_status:文章状态(publish/auto-draft/inherit等)  comment_status:评论状态(open/closed)  ping_status:PING状态(open/closed)  post_password:文章密码  post_name:文章缩略名  to_ping:未知  pinged:已经PING过的链接  post_modified:修改时间  post_modified_gmt:修改时间(GMT+0时间)  post_content_filtered:未知  post_parent:父文章,主要用于PAGE  guid:未知  menu_order:排序ID  post_type:文章类型(post/page等)  post_mime_type:MIME类型  comment_count:评论总数    wp_terms  term_id:分类ID  name:分类名  slug:别名  term_group:未知    wp_term_relationships  object_id:对应文章ID/链接ID  term_taxonomy_id:对应分类方法ID  term_order:排序    wp_term_taxonomy  term_taxonomy_id:分类方法ID  term_id:分类id  taxonomy:分类方法(category/post_tag)  description:未知  parent:所属父分类方法ID  count:文章数统计 

查看更多关于wordpress 数据库表结构 - WordPress的详细内容...

  阅读:52次