[WordPress] 外掛分享: Custom Post Type Tables

前言介紹

  • 這款 WordPress 外掛「Custom Post Type Tables」是 2023-03-29 上架。 目前已經下架不再更新,不建議安裝使用。
  • 目前有 60 個安裝啟用數。
  • 上一次更新是 2023-05-04,距離現在已有 731 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 5.9 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 7.1 以上。
  • 有 3 人給過評分。
  • 論壇上目前有 2 個提問,問題解答率 0%

外掛協作開發者

sebastianklaus |

外掛標籤

cms | cpt | post | types | custom post types |

內容簡介

WordPress的自訂文章類型通常會儲存在默認的文章表格中,但當網站有大量自訂文章類型時,查詢會變得非常昂貴,特別是涉及到生成元數據的外掛。因此,將數據拆分到單獨的表格中,可以加快查詢速度,改善組織和管理內容,和提高網站安全性。此外,外掛會自動重寫查詢來使用自定義表格,可與Multisite安裝、WooCommerce和Advanced Custom Fields一起使用。使用此外掛還可以增強WordPress的處理速度,並改進網站性能和安全性。

問題與答案:
- WordPress的自訂文章類型通常儲存在哪個表格中?
答:默認的文章表格(通常為wp_posts)中。
- 當網站有大量自訂文章類型時,查詢會變得昂貴的情況通常涉及哪些外掛?
答:生成元數據的外掛,例如Advanced Custom Fields。
- 把數據拆分到單獨的表格中,可以有哪些好處?
答:可以加快查詢速度、改善組織和管理內容,提高網站安全性。
- 使用此外掛需要注意哪些事項?
答:選擇自訂文章類型後,會在數據庫中創建一個新表格並轉移數據;請事先備份數據庫以避免意外情況發生;在編寫自己的查詢時,尽量指定所需的自訂文章類型來減少不必要的查詢。

原文外掛簡介

WordPress stores custom post types in the default posts table (typically wp_posts), which is fine for most setups. In the majority of use cases, WordPress sites are not used to store in excess of thousands of posts, and so this sort of setup doesn’t place much additional load on servers.
In cases where the site generates a significant amount of posts across multiple post types though, queries can become very expensive – especially where meta generating plugins such as Advanced Custom Fields are involved. Where a WordPress site is expected to generate thousands of posts (and subsequently, many thousands of rows of post meta) queries can be sped up significantly by splitting out data into separate tables. This plugin splits out data by post type, creating additional tables for each custom post type used. A ‘product’ custom post type for example will have its posts stored in product and its meta in product_meta.
If you are using WordPress a little bit longer, you already know that it is an incredibly versatile platform. With its numerous features and extensions, however, it can sometimes be difficult to keep track of and find the right method for managing your content. This is where the use of WordPress custom post types in separate tables comes in!
By outsourcing your custom post types to separate tables, you can better organize and manage your content. It also allows you to have better control over your database and process queries more quickly and efficiently, which can positively impact the performance of your website.
Moreover, outsourcing custom post types to separate tables can also help improve the security of your website. By separating your content into separate tables, you can prevent malware or hackers from accessing your entire database.
Overall, outsourcing WordPress custom post types to separate tables offers a range of benefits for your website. It can improve the organization and management of your content, optimize the performance of your website, and increase your security. If you want to take your website to the next level, you should consider outsourcing your custom post types to separate tables!
Works with

Multisite Installations
Woocommerce
YOAST etc.
Advanced Custom Fields
… and all other registered active custom post types

Settings
As soon as you select a Custom Post Type, a new table is created in the database. This table will be used for all entries of this custom post type.
When you migrate the existing entries, the data from the old table is copied to the new table. This process is not reversible.
Backup your database before migrating in case something doesn’t work as you expect.
Implementation
Each new post and meta table is created to the same structure as the WordPress default post and meta tables. This streamlines the storage process and means that WordPress is capable of interpreting the data wherever it would normally use a wp_posts row, e.g. on the admin edit post pages, admin post listing pages, and in the wp-posts functions (e.g. get_post()).
When new posts are created, a row is inserted into the wp_posts table (as normal) and an automatic MySQL trigger is used to copy this data into the new custom table. Queries to the wp_posts and wp_postmeta table are then rewritten to use the custom table, so that all future lookups and updates made by WordPress and its plugins are made to the new tables. The original wp_posts row is retained for lookup purposes, so that we can determine the post type (and therefore custom table) when there is only a post ID available to work with. Since these lookups are (usually) only necessary in the WordPress admin and exclusively use the primary key, they do not significantly increase the load of the request. Additionally, each ID lookup is made a maximum of once per request and the result is cached on a per-request basis.
To minimise unecessary lookups when writing your own queries, specify the post type you are looking for whenever possible. This will allow the plugin to simply parse the table from the query without having to lookup the post type in the wp_posts table.
Filter Hooks
cpt_tables:settings_capability:
Customise what capability the settings page should be limited to. Default is ‘manage_options’.
Contribute
Developed with ♥ by Sebastian.
This plugin was initially created for own usage to get a big database cleaner.
Check out the GitHub repository and submit pull requests or open issues
1.2.6

Find orphaned meta values and copy to new custom table
Trigger optimization

1.2.5.2

Hotfix: Altered correct auto_increment field for meta table

1.2.5

Removed autoincrement from copied table as it is controles by the posts_table (Revert CPT Tables and migrate them again to get the changes working)

1.2.4

Bugfix in cleanup-cronjob

1.2.3

Revert tables on plugin deactivation

1.2.2

German translation
Add missing migrated post_types, when the custom table exists
Fixed bug on deactivate the plugin

1.2.1

Load plugin the right time when all post types are registered
Refactoring and bugfixing
Added language pot template

1.1.0

Clear orphaned post_types from activated entries
You can activate a cronjob for table optimization in the settings

1.0.9

Automatically remove orphaned entries in the main post table under certain conditions

1.0.8

Re-create triggers if they don’t exist

1.0.7

tested with WordPress 6.2

1.0.6

Fixed debugger warnings
Clean up code
Escape vars
Sanitize vars
Refactoring

1.0.1

Added _ to accepted chars of post type

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Custom Post Type Tables」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.0.6 | 1.0.7 | 1.0.8 | 1.0.9 | 1.1.0 | 1.2.1 | 1.2.2 | 1.2.3 | 1.2.4 | 1.2.5 | 1.2.6 | trunk | 1.0.10 | 1.2.5.1 | 1.2.5.2 |

延伸相關外掛(你可能也想知道)

  • Custom Post Type UI 》Custom Post Type UI 提供了易於使用的界面,以便為您的網站註冊和管理自定義文章類型和分類法。, Custom Post Type UI Extended, CPTUI 協助建立自定義內容...。
  • Post Type Switcher 》這個外掛在文章編輯介面中新增了一個簡單的文章型別下拉選單,讓你可以重新指派任何文章至新的文章型別。你可以在編輯文章時更換文章的型別。, 支援的型別, ...。
  • Essential Content Types 》Essential Content Types 是一個 WordPress 外掛程式,讓您可以在您的網站上以不同的內容/文章類型展示出優秀的內容。這些內容/文章類型可能會被 WordPress ...。
  • MAS Static Content 》MAS Static Content 是一款免費的 WordPress 外掛,可讓你建立自訂文章型態的靜態內容,並使用 shortcode 嵌入網頁。, 使用 [mas_static_content] shortcode ...。
  • Post Types Unlimited 》Post Types Unlimited 是一個輕鬆的方式,可以以正確的方式向你的 WordPress 網站添加自訂文章類型和自訂分類法 (taxonomy)。此外,這個外掛與任何佈景主題都...。
  • Post Type Transfer 》這個外掛允許使用者彈性地將文章從一種文章類型轉換為另一種。此外,使用者也可以將文章從文章類型轉換為頁面。, 功能, • 安裝簡易, • 將文章轉換為其他...。
  • Search Widget Post Types for Elementor 》此外掛為Elementor新增選項,讓搜尋元件只搜尋特定的文章類型,例如WooCommerce產品或自訂文章類型。。
  • WordPress Calendar For Custom Post Types 》一個新的小工具,可基於現有的文章類型顯示日曆。, , 選擇任何可用的文章類型進行顯示, 按選定的文章類型所綁定的自定義分類法規篩選, 在日曆下方最多列出10...。
  • Easy PayPal Custom Fields 》此外掛可讓您非常輕易地於您的網站或部落格上加入 PayPal 按鈕。您無需記得複雜的快捷語法(或是教給使用者)。, 您可以選擇要在哪種型態的文章(包括自訂文...。
  • Custom Post Type Changer 》這個外掛允許你切換 WordPress 文章類型,提供了快速編輯和批次編輯的選項。, 這個外掛只是在編輯文章頁面右上方的「立即發布」功能下添加了一個功能。, 你可...。
  • Content Template Widget for Toolset Views 》內容模板小工具(Content Template Widget) (先前稱為 View Template Widget),可用於在主題小工具區域中插入與當前文章相關的訊息框。可以設定每個小工具要顯...。
  • Easy Custom Post Type UI 》Easy Custom Post Type UI 提供了一個簡單易用的介面,用於在您的網站上建立和維護分類和自定義文章類型。, 這個外掛只使用 WordPress 核心內的原生函數撰寫...。
  • TypeRocket UI 》使用 TypeRocket UI 外掛,您可以在不需要任何程式碼的情況下,將自定義文章類型和分類方式新增到您的網站中。此外,TypeRocket UI 外掛不僅提供一般文章類型...。
  • Sharedaddy More Control 》您無法僅限於文章或頁面使用 Sharedaddy。這就是為什麼此外掛存在的原因,現在您也可以控制 Sharedaddy 中的文章類型。。
  • WpPDE 》WpPDE 是一個針對 WordPress 的開發環境。您可以使用 WpPDE 創建自己的外掛程式並通過它進行維護。, WpPDE 可以讓您創建包含以下內容的外掛程式:, , 小工具,...。

文章
Filter
Apply Filters
Mastodon