【问题标题】:How to add extra columns to wp_posts table in Wordpress?如何在 Wordpress 中向 wp_posts 表添加额外的列?
【发布时间】:2019-11-12 12:26:52
【问题描述】:

是否可以在 WordPress Posts 表中添加额外的列,然后使用选择查询?

选择查询将如何?

【问题讨论】:

  • 可能吗?是的,有可能,但我很好奇你为什么要这样做?

标签: php sql wordpress post select


【解决方案1】:

我会推荐 wp post meta。请参阅下面的链接。

https://developer.wordpress.org/cli/commands/post/meta/ https://codex.wordpress.org/Class_Reference/WP_Meta_Query

# Set post meta
$ wp post meta set 123 _wp_page_template about.php
Success: Updated custom field '_wp_page_template'.

# Get post meta
$ wp post meta get 123 _wp_page_template
about.php

# Update post meta
$ wp post meta update 123 _wp_page_template contact.php
Success: Updated custom field '_wp_page_template'.

# Delete post meta
$ wp post meta delete 123 _wp_page_template
Success: Deleted custom field.

问候。 编。

【讨论】:

  • 这是正确的做法; WordPress 已经为您提供了元表来存储所有类型记录所需的任何额外数据,无需修改数据库架构。
猜你喜欢
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 2021-09-29
  • 1970-01-01
  • 1970-01-01
  • 2020-12-17
  • 1970-01-01
  • 2012-01-19
相关资源
最近更新 更多