当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - Edit database table values using Wordpress Custom Fields

问题描述:

Wordpress noob here.

I have a 1NF database with information that I need to make easily editable. I've heard that Wordpress custom fields could be useful.

I'm not at all experienced with Wordpress custom fields/repeater fields, so what I need is resources/links that would help as I'm not even sure where to start here.

My current WP knowlege:

- create basic theme

- create very basic plugin (learned from online tuts)

- basic operations in admin panel (add/edit page/post)

The tables that I've added to the wordpress database are similar to the following:

Foods

+----+-------+--------------+-----+

|id |name |description |type |

+----+-------+--------------+-----+

|1 |apple |apple desc.. |1 |

+----+-------+--------------+-----+

|2 |orange |orange desc.. |2 |

+----+-------+--------------+-----+

|3 |pear |pear desc.. |1 |

+----+-------+--------------+-----+

FoodTypes

+----+-------------------+

|id |type_description |

+----+-------------------+

|1 |the desc.. |

+----+-------------------+

|2 |the desc.. |

+----+-------------------+

I could create a custom interface which would update these values using php and mySql but I really want to bite into WP now.

So using:

" SELECT Foods.name, Foods.description, FoodTypes.type_description AS type

FROM Foods

LEFT JOIN FoodTypes

ON Foods.type = FoodTypes.id "

I can get the values that the user needs to 'see'

Then using:

" UPDATE Foods

LEFT JOIN FoodTypes

ON Foods.type = FoodTypes.id

SET Foods.name = :name,

Foods.description = :desc,

Foods.type = :type

WHERE Foods.id = :id AND FoodTypes.type_description = :type_desc "

... or something along those lines (mySql noob too)

Which would be the best approach using Wordpress custom fields to accomplish this? Do you know of any good reads/resources available that are specific to this task?

网友答案:

"Custom fields" are post meta data stored in the wp_postmeta table.

If you want to write to non-core DB tables with WordPress, make use of the WP_Query class.

网友答案:

From what you are describing you would want to create a Custom post type called Food, and a custom taxonomy called Food type.

I would advise you start with the following codex articles.

https://codex.wordpress.org/Post_Types#Custom_Post_Types

https://codex.wordpress.org/Taxonomies#Custom_Taxonomies

There are plugins that would help you achieve this with click and play, however in the end you may need to programmatically register the custom post type and taxonomy, depending on how much control you need over the queries etc.

The following plugin can push you in the right direction: https://wordpress.org/plugins/types/

分享给朋友:
您可能感兴趣的文章:
随机阅读: