amM
amM

Reputation: 529

Retrieving data from wp_terms table in WordPress

I am new to WordPress. I am creating admin panel like WordPress in codeigniter, so I need to understand database table relationships in WordPress. There is a database table wp_terms which is used to store categories and tags.

My question or what I want is I want to to display categories and tags by their posts.

e.g. : Suppose I have inserted 4 new posts which are having categories and tags. posts will be stored in wp_posts table and categories and tags will be stored in wp_terms. So what is a relation between both tables.
Please Help me.
Thanks.

Upvotes: 1

Views: 2566

Answers (2)

Deep Kakkar
Deep Kakkar

Reputation: 6305

The categories for both posts and links and the tags for posts are found within the wp_terms table.

The core of the WordPress data is the posts. It is stored in the wp_posts table. Also Pages and navigation menu items are stored in this table.

Posts are associated with categories and tags from the wp_terms table and this association is maintained in the wp_term_relationships table. The association of links to their respective categories are also kept in this table.

For more details between the relations of tables you can see the image below: enter image description here

In case if you wants to see the relationship between all the tables then see the image as below:

enter image description here

To get the more details about the wordpress database tables , you can see the Link

e.g. want to to display categories and tags by their posts.

<?php $terms = wp_get_post_terms( $post_id, $taxonomy, $args ); ?>

If you want to use custom query then call $wpdb global variable.

global $wpdb;
$query= 'write query there' ;

Thank you!

Upvotes: 6

Dipen Desai
Dipen Desai

Reputation: 149

try this

<?php $terms = wp_get_post_terms( $post_id, $taxonomy, $args ); ?>

Upvotes: 1

Related Questions