admin管理员组

文章数量:1435534

I have decided to redesign a plug I developed to use custom post types and custom fields instead of custom tables in the database.

I have some questions about abstracting data into new post types. These questions are based on the assumption that I should essentially be trying to replicate a relational database.

It's a dictionary feature for a language learning blog. Here are the tables from the original. Simplified for readability.

CREATE TABLE words (
    ID int(),
    word varchar(),
    parent_id int()
);

CREATE TABLE nouns (
    word_id int(),
    plural varchar(),
    [...]
);

CREATE TABLE verbs (
    word_id int(),
    pres_part varchar(),
    past_part varchar(),
    [...]
);

CREATE TABLE definitions (
    ID int(),
    word_id int(),
    definition varchar(),
    [...]
);

CREATE TABLE examples (
    ID int(),
    defintion_id int(),
    example varchar(),
    [...]
);

Words will obviously be the first custom post type.

I've decided to use custom fields for the noun and verb information as they are 1:1 relationships and only existed to reduce null entries in the words table. I believe WordPress will only create an entry in the postmeta table if the fields are actually used. So that would solve that problem.

Now the main question is; should I store definitions and examples as custom post types as I would in a relational database or just use ACF repeaters? These are both genuine 1-many relationships. Although a single definition will probably only ever have a maximum of 3 examples.

The reader might wish to search for keywords within the definitions and/or examples but they would never want to view a single definition as page.

Definitions and examples might however be used outside the context of their respective word in the future. With a flashcard app for example. Is it easy to uniquely identify and request a single entry from a repeater?

本文标签: custom post typescustom fields and normalization