Casper009
Casper009

Reputation: 67

Movable Type: Category relationships

I would like to know the relationships of Category in MovableType CMS.

Currently, I have 2 categories named "Category A" and "Category B". And I have Blog named "Blog A". "Category A" and "Category B" are in "Blog A". When I create "Entry 1" under "Blog A", I have chose "Category A" for that "Entry 1". But when I checked in database, I could see that column name "entry_category_id" under "mt_entry" table is "NULL".

What I'm trying to do is, I would like to retrieve every entries under "Category A". Please let me know if I should search in different table under MovableType database for those entries under specific Category.

Thanks in advance.

Upvotes: 4

Views: 387

Answers (2)

Maarten Schenk
Maarten Schenk

Reputation: 41

Or, if you want to do it all in one query, try this:

SELECT entry_id, entry_title
FROM mt_entry, mt_placement, mt_category
WHERE mt_entry.entry_id = mt_placement.placement_entry_id
AND mt_placement.placement_category_id = mt_category.category_id
AND mt_category.category_label =  'YOURCATEGORYLABELGOESHERE';

(replace YOURCATEGORYLABELGOESHERE with the name of the category you want)

This will return a list of all entries (and their id's) in that category.

Note, if you have multiple blogs that have categories with the same name, you might need to add an extra line to select just the entries from blogs you want, something like

AND mt_category.blog_id = 2

or

AND mt_category.blog_id in (2, 5, 7)

Upvotes: 2

The column mt_entry.entry_category_id is unused (I guess it's a remnant from an old schema version). The categories associated to an entry are stored in the mt_placement table.

To retrieve every entries under a specific category, first find the category ID (it's unique across all blogs, either look it up via the category listing using the id parameter in the URL or search the mt_category table), then do a query like this one:

SELECT placement_entry_id from mt_placement WHERE placement_category_id = <your category numeric ID>;

You'll get a list of entry IDs associated to that category.

Upvotes: 5

Related Questions