Support » Fixing WordPress » A wordpress database question wp_terms_relationships

  • zerackam

    (@zerackam)


    Hi so i have created a wordpress site and loaded all of the posts and categories through mysql using a program called sqlyog. I am having one problem i was hoping someone could clarify.

    From what i understand in wordpress the database table wp_terms_relationships holds each post and its associated category. the headings in this table are
    object_id term_taxonomy_id term_order

    where
    object_id seem to be the unique post id or just the same as the id field from the wp_posts table.
    term_taxonomy_id is the term the categories the object_id or unique post is associated with. is this correct?

    The problem im having is when i try to associate more than 1 category with a post. ie lets say 10=baseball bats and 20=footballs
    so i enter 10,20 in the term_taxonomy_id field it doesnt work and only 1 number is accepted. the field only takes one number. So im confused as to the structure of these three tables and where to enter associated categories for posts.

    Additionally

    this is what i think the following tables are for

    wp_terms table
    term_id name field: a unique number given a category
    name: name of category ie)baseball hats
    slug field: ie) baseball_hats

    wp_terms_taxonomy table
    term_taxonomy_id field: unique number given here
    term_id: is the unique number given to a category in the wp_terms table
    taxonomy: is the type of category is a post category or page category
    description: desc of a category
    parent: is the category is a child or a parent of others
    count: how many posts in category

    Bottom line: where is the wordpress database can i ascribe multiple categories to a post.

    Thanks.

Viewing 1 replies (of 1 total)
  • wpfan1000

    (@wpfan1000)

    Hi,

    I didn’t know myself how this works, so I tested it out as follows:

    Opened with a viewer the wp_term_relationships table
    Added a post in WP dashboard, post id = 8
    Added 3 categories to the post, with ids 2,3 and 4
    Refreshed the view of the table
    The post id shows up in the object_id column in 3 rows and each row has a different category id in the term_taxonomy_id field

    In other words, to attach multiple categories to a post you need to enter a row for each category, with the same post id in the object_id column and a different category id in the term_taxonomy_id column

    Hope this helps 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘A wordpress database question wp_terms_relationships’ is closed to new replies.