{"id":4739,"date":"2025-10-20T16:58:14","date_gmt":"2025-10-20T08:58:14","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4739.html"},"modified":"2025-10-20T16:58:15","modified_gmt":"2025-10-20T08:58:15","slug":"%e4%b8%bawordpress%e8%87%aa%e5%ae%9a%e4%b9%89%e6%96%87%e7%ab%a0%e7%b1%bb%e5%9e%8b%e6%b7%bb%e5%8a%a0%e6%a0%87%e7%ad%be%ef%bc%88%e9%bb%98%e8%ae%a4%e5%88%86%e7%b1%bb%e6%b3%95%ef%bc%89%e7%9a%84%e5%ae%9e","status":"publish","type":"bjjc","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4739.html","title":{"rendered":"\u4e3aWordPress\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u6dfb\u52a0\u6807\u7b7e\uff08\u9ed8\u8ba4\u5206\u7c7b\u6cd5\uff09\u7684\u5b9e\u73b0\u65b9\u6cd5\u53ca\u4ee3\u7801"},"content":{"rendered":"<p>\u5c06WordPress\u9ed8\u8ba4\u7684\u201c\u6807\u7b7e\u201d\uff08post_tag\uff09\u5206\u7c7b\u6cd5\u6dfb\u52a0\u5230\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff08CPT\uff09\u4e0a\uff0c\u662f\u4e00\u4e2a\u5e38\u89c1\u4e14\u5b9e\u7528\u7684\u9700\u6c42\u3002\u65e0\u8bba\u662f<strong>\u5df2\u7ecf\u521b\u5efa<\/strong>\u8fd8\u662f<strong>\u672a\u6765\u5c06\u8981\u521b\u5efa<\/strong>\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff0c\u90fd\u6709\u76f8\u5e94\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p><h2 class=\"wp-block-heading\">\u65b9\u6cd5\u4e00\uff1a\u6ce8\u518c\u65b0\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u65f6\u76f4\u63a5\u6dfb\u52a0<\/h2><p>\u5982\u679c\u4f60<strong>\u5c1a\u672a\u521b\u5efa<\/strong>\u6216<strong>\u6b63\u5728\u521b\u5efa<\/strong>\u65b0\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff0c\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u5728 <code>register_post_type<\/code> \u51fd\u6570\u7684 <code>taxonomies<\/code> \u53c2\u6570\u4e2d\u660e\u786e\u58f0\u660e\u652f\u6301 <code>post_tag<\/code>\u3002<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u6ce8\u518c\u4e00\u4e2a\u540d\u4e3a 'my_custom_post' \u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u5e76\u652f\u6301\u9ed8\u8ba4\u6807\u7b7e\n *\/\nfunction register_my_custom_post_type() {\n    $args = array(\n        'labels'             =&gt; array(\n            'name'               =&gt; '\u81ea\u5b9a\u4e49\u6587\u7ae0',\n            'singular_name'      =&gt; '\u81ea\u5b9a\u4e49\u6587\u7ae0',\n            \/\/ ... \u5176\u4ed6\u6807\u7b7e\u9879\n        ),\n        'public'             =&gt; true,\n        'publicly_queryable' =&gt; true,\n        'show_ui'            =&gt; true,\n        'show_in_menu'       =&gt; true,\n        'query_var'          =&gt; true,\n        'rewrite'            =&gt; array( 'slug' =&gt; 'my-custom-post' ),\n        'capability_type'    =&gt; 'post',\n        'has_archive'        =&gt; true,\n        'hierarchical'       =&gt; false,\n        'menu_position'      =&gt; null,\n        'supports'           =&gt; array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),\n        \/\/ \u8fd9\u662f\u5173\u952e\uff1a\u5728 taxonomies \u6570\u7ec4\u4e2d\u6dfb\u52a0 'post_tag'\n        'taxonomies'         =&gt; array( 'category', 'post_tag' ), \/\/ \u53ef\u4ee5\u540c\u65f6\u6dfb\u52a0\u9ed8\u8ba4\u7684'category'\u548c'post_tag'\n    );\n    register_post_type( 'my_custom_post', $args );\n}\nadd_action( 'init', 'register_my_custom_post_type' );<\/code><\/pre><p><strong>\u5173\u952e\u53c2\u6570\u89e3\u91ca<\/strong>\uff1a<\/p><ul class=\"wp-block-list\">\n<li><code>'taxonomies' =&gt; array( 'post_tag' )<\/code>\uff1a\u8fd9\u884c\u4ee3\u7801\u544a\u8bc9WordPress\uff0c\u5c06\u8fd9\u4e2a\u540d\u4e3a <code>my_custom_post<\/code> \u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u4e0e <code>post_tag<\/code> \u5206\u7c7b\u6cd5\u5173\u8054\u8d77\u6765\u3002<\/li>\n\n\n\n<li>\u4f60\u4e5f\u53ef\u4ee5\u540c\u65f6\u6dfb\u52a0\u591a\u4e2a\u5206\u7c7b\u6cd5\uff0c\u4f8b\u5982 <code>array( 'category', 'post_tag' )<\/code> \u4f1a\u8ba9\u8fd9\u4e2aCPT\u540c\u65f6\u652f\u6301\u9ed8\u8ba4\u7684\u201c\u5206\u7c7b\u201d\u548c\u201c\u6807\u7b7e\u201d\u3002<\/li>\n<\/ul><h2 class=\"wp-block-heading\">\u65b9\u6cd5\u4e8c\uff1a\u4e3a\u5df2\u5b58\u5728\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u8ffd\u52a0\u6807\u7b7e<\/h2><p>\u5982\u679c\u4f60\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b<strong>\u5df2\u7ecf\u6ce8\u518c\u5b8c\u6210<\/strong>\uff0c\u6216\u8005\u4f60\u4e0d\u60f3\u4fee\u6539\u539f\u59cb\u7684\u6ce8\u518c\u4ee3\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>register_taxonomy_for_object_type<\/code> \u51fd\u6570\u5c06\u73b0\u6709\u7684 <code>post_tag<\/code> \u5206\u7c7b\u6cd5\u6302\u8f7d\u5230\u6307\u5b9a\u7684CPT\u4e0a\u3002<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u4e3a\u5df2\u5b58\u5728\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b 'my_existing_cpt' \u6dfb\u52a0\u9ed8\u8ba4\u6807\u7b7e\u652f\u6301\n *\/\nfunction add_post_tag_to_existing_cpt() {\n    \/\/ \u5c06 'post_tag' \u6302\u8f7d\u5230\u4f60\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\n    register_taxonomy_for_object_type( 'post_tag', 'my_existing_cpt' );\n}\n\/\/ \u5728 'init' \u52a8\u4f5c\u94a9\u5b50\u4e4b\u540e\u6267\u884c\uff0c\u786e\u4fdd\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u5df2\u88ab\u6ce8\u518c\nadd_action( 'init', 'add_post_tag_to_existing_cpt', 999 );<\/code><\/pre><p><strong>\u5173\u952e\u70b9\u89e3\u91ca<\/strong>\uff1a<\/p><ul class=\"wp-block-list\">\n<li><code>register_taxonomy_for_object_type( 'post_tag', 'my_existing_cpt' )<\/code>\uff1a\u8fd9\u4e2a\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u662f\u5206\u7c7b\u6cd5\u7684\u540d\u79f0\uff08<code>post_tag<\/code>\uff09\uff0c\u7b2c\u4e8c\u4e2a\u662f\u4f60\u8981\u6302\u8f7d\u7684\u76ee\u6807\u6587\u7ae0\u7c7b\u578b\u7684\u540d\u79f0\uff08\u4f8b\u5982 <code>my_existing_cpt<\/code>\uff09\u3002<\/li>\n\n\n\n<li><code>add_action( 'init', 'add_post_tag_to_existing_cpt', 999 )<\/code>\uff1a\u5c06\u51fd\u6570\u6302\u8f7d\u5230 <code>init<\/code> \u52a8\u4f5c\u94a9\u5b50\u4e0a\uff0c\u5e76\u8bbe\u7f6e\u4e00\u4e2a\u8f83\u5927\u7684\u4f18\u5148\u7ea7\u6570\u5b57\uff08\u5982999\uff09\uff0c\u662f\u4e3a\u4e86\u786e\u4fdd\u8fd9\u4e2a\u64cd\u4f5c\u5728\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b<strong>\u672c\u8eab\u88ab\u6ce8\u518c\u4e4b\u540e<\/strong>\u518d\u6267\u884c\uff0c\u8fd9\u6837\u624d\u6709\u6548\u3002<\/li>\n<\/ul><h2 class=\"wp-block-heading\">\u65b9\u6cd5\u4e09\uff1a\u4e00\u52b3\u6c38\u9038\u7684\u65b9\u6cd5\uff08\u9002\u7528\u4e8e\u5df2\u5b58\u5728\u548c\u672a\u6765\u521b\u5efa\u7684CPT\uff09<\/h2><p>\u5982\u679c\u4f60\u60f3\u786e\u4fdd<strong>\u6240\u6709<\/strong>\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff08\u5305\u62ec\u5c06\u6765\u7531\u5176\u4ed6\u63d2\u4ef6\u521b\u5efa\u7684\u7c7b\u578b\uff09\u90fd\u9ed8\u8ba4\u652f\u6301\u6807\u7b7e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u66f4\u901a\u7528\u7684\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u4f1a\u5728\u6bcf\u6b21CPT\u88ab\u6ce8\u518c\u65f6\uff0c\u81ea\u52a8\u4e3a\u5176\u8ffd\u52a0 <code>post_tag<\/code> \u652f\u6301\u3002<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u901a\u7528\u65b9\u6cd5\uff1a\u4e3a\u6240\u6709\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff08\u5305\u62ec\u672a\u6765\u521b\u5efa\u7684\uff09\u81ea\u52a8\u6dfb\u52a0\u9ed8\u8ba4\u6807\u7b7e\u652f\u6301\n * \u6392\u9664\u5185\u7f6e\u7684\u6587\u7ae0\u7c7b\u578b\uff08\u5982post, page\uff09\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u8986\u76d6\n *\/\nfunction add_post_tag_to_all_cpts( $post_type, $args ) {\n    $built_in_post_types = array( 'post', 'page', 'attachment', 'revision', 'nav_menu_item' );\n\n    \/\/ \u5982\u679c\u662f\u5185\u7f6e\u6587\u7ae0\u7c7b\u578b\uff0c\u5219\u8df3\u8fc7\n    if ( in_array( $post_type, $built_in_post_types ) ) {\n        return;\n    }\n\n    \/\/ \u4e3a\u8fd9\u4e2a\u65b0\u6ce8\u518c\u7684CPT\u6dfb\u52a0post_tag\u652f\u6301\n    register_taxonomy_for_object_type( 'post_tag', $post_type );\n}\n\/\/ \u4f7f\u7528 'registered_post_type' \u52a8\u4f5c\u94a9\u5b50\uff0c\u5728\u6bcf\u4e2a\u6587\u7ae0\u7c7b\u578b\u6ce8\u518c\u5b8c\u6210\u540e\u89e6\u53d1\nadd_action( 'registered_post_type', 'add_post_tag_to_all_cpts', 10, 2 );<\/code><\/pre><p><strong>\u5173\u952e\u70b9\u89e3\u91ca<\/strong>\uff1a<\/p><ul class=\"wp-block-list\">\n<li><code>registered_post_type<\/code>\uff1a\u8fd9\u4e2a\u52a8\u4f5c\u94a9\u5b50\u5728\u6bcf\u4e2a\u6587\u7ae0\u7c7b\u578b\u901a\u8fc7 <code>register_post_type<\/code> \u6210\u529f\u6ce8\u518c\u540e\u90fd\u4f1a\u88ab\u8c03\u7528\u3002<\/li>\n\n\n\n<li>\u51fd\u6570\u63a5\u6536\u4e24\u4e2a\u53c2\u6570\uff1a<code>$post_type<\/code>\uff08\u65b0\u6ce8\u518c\u7684\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\uff09\u548c <code>$args<\/code>\uff08\u6ce8\u518c\u65f6\u4f20\u9012\u7684\u53c2\u6570\u6570\u7ec4\uff09\u3002<\/li>\n\n\n\n<li><code>$built_in_post_types<\/code>\uff1a\u4e00\u4e2a\u6570\u7ec4\uff0c\u5305\u542b\u4e86WordPress\u6240\u6709\u5185\u7f6e\u7684\u6587\u7ae0\u7c7b\u578b\u3002\u6211\u4eec\u6392\u9664\u5b83\u4eec\uff0c\u4ee5\u514d\u5e72\u6270\u6838\u5fc3\u529f\u80fd\u3002<\/li>\n\n\n\n<li>\u5bf9\u4e8e\u4efb\u4f55\u65b0\u6ce8\u518c\u7684\u3001\u975e\u5185\u7f6e\u7684\u6587\u7ae0\u7c7b\u578b\uff0c\u51fd\u6570\u90fd\u4f1a\u81ea\u52a8\u6267\u884c <code>register_taxonomy_for_object_type( 'post_tag', $post_type )<\/code>\u3002<\/li>\n<\/ul><h2 class=\"wp-block-heading\">\u65b9\u6cd5\u56db\uff1a\u8fdb\u9636\u7bc7\uff01\u4e0d\u4f9d\u8d56\u786c\u7f16\u7801\uff0c\u4e00\u52b3\u6c38\u9038\uff01<\/h2><p>\u4f7f\u7528\u786c\u7f16\u7801\uff08hard-coded\uff09\u7684\u5185\u7f6e\u6587\u7ae0\u7c7b\u578b\u5217\u8868\u786e\u5b9e\u4e0d\u591f\u7075\u6d3b\uff0c\u5982\u679cWordPress\u672a\u6765\u6dfb\u52a0\u4e86\u65b0\u7684\u5185\u7f6e\u7c7b\u578b\uff0c\u8fd9\u6bb5\u4ee3\u7801\u5c31\u9700\u8981\u66f4\u65b0\u3002\u8fd9\u662f\u4e00\u79cd\u66f4\u4f18\u96c5\u3001\u66f4\u5065\u58ee\u7684\u65b9\u6cd5\u6765\u5224\u65ad\u4e00\u4e2a\u6587\u7ae0\u7c7b\u578b\u662f\u5426\u4e3a\u5185\u7f6e\u7c7b\u578b\u3002<\/p><h3 class=\"wp-block-heading\">\u4f7f\u7528 <code>_builtin<\/code> \u5c5e\u6027\uff08\u63a8\u8350\uff09<\/h3><p>\u5728\u6ce8\u518c\u6587\u7ae0\u7c7b\u578b\u65f6\u6216\u901a\u8fc7 <code>get_post_type_object()<\/code> \u83b7\u53d6\u6587\u7ae0\u7c7b\u578b\u5bf9\u8c61\u65f6\uff0c\u5185\u7f6e\u6587\u7ae0\u7c7b\u578b\u7684\u5bf9\u8c61\u4f1a\u5305\u542b\u4e00\u4e2a <code>_builtin<\/code> \u5c5e\u6027\u4e14\u503c\u4e3a <code>true<\/code>\u3002<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u901a\u7528\u65b9\u6cd5\uff1a\u4e3a\u6240\u6709\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u81ea\u52a8\u6dfb\u52a0\u9ed8\u8ba4\u6807\u7b7e\u652f\u6301\uff08\u4f7f\u7528 _builtin \u5c5e\u6027\u5224\u65ad\uff09\n *\/\nfunction add_post_tag_to_all_cpts( $post_type, $args ) {\n    \/\/ \u83b7\u53d6\u6587\u7ae0\u7c7b\u578b\u5bf9\u8c61\n    $post_type_object = get_post_type_object( $post_type );\n\n    \/\/ \u5982\u679c\u6587\u7ae0\u7c7b\u578b\u662f\u5185\u7f6e\u7684\uff0c\u5219\u8df3\u8fc7\n    if ( $post_type_object &amp;&amp; $post_type_object-&gt;_builtin ) {\n        return;\n    }\n\n    \/\/ \u4e3a\u8fd9\u4e2a\u65b0\u6ce8\u518c\u7684\u975e\u5185\u7f6eCPT\u6dfb\u52a0post_tag\u652f\u6301\n    register_taxonomy_for_object_type( 'post_tag', $post_type );\n}\nadd_action( 'registered_post_type', 'add_post_tag_to_all_cpts', 10, 2 );<\/code><\/pre><p><strong>\u4f18\u70b9<\/strong>\uff1a<\/p><ul class=\"wp-block-list\">\n<li><strong>\u52a8\u6001\u5224\u65ad<\/strong>\uff1a\u4e0d\u4f9d\u8d56\u4e8e\u786c\u7f16\u7801\u7684\u5217\u8868\uff0c\u81ea\u52a8\u9002\u5e94WordPress\u6838\u5fc3\u7684\u4efb\u4f55\u53d8\u5316<\/li>\n\n\n\n<li><strong>\u4ee3\u7801\u66f4\u7b80\u6d01<\/strong>\uff1a\u4e0d\u9700\u8981\u7ef4\u62a4\u4e00\u4e2a\u53ef\u80fd\u8fc7\u65f6\u7684\u5185\u7f6e\u7c7b\u578b\u5217\u8868<\/li>\n\n\n\n<li><strong>\u66f4\u51c6\u786e<\/strong>\uff1a\u6db5\u76d6\u4e86\u6240\u6709\u771f\u6b63\u5185\u7f6e\u7684\u7c7b\u578b\uff0c\u5305\u62ec\u90a3\u4e9b\u4e0d\u5e38\u7528\u7684<\/li>\n<\/ul><h3 class=\"wp-block-heading\">\u7ed3\u5408\u4f7f\u7528 <code>_builtin<\/code> \u548c\u6392\u9664\u7279\u5b9a\u7c7b\u578b<\/h3><p>\u5982\u679c\u4f60\u786e\u5b9e\u9700\u8981\u6392\u9664\u67d0\u4e9b\u7279\u5b9a\u7684\u975e\u5185\u7f6e\u6587\u7ae0\u7c7b\u578b\uff08\u6bd4\u5982\u67d0\u4e9b\u63d2\u4ef6\u521b\u5efa\u7684\u4f60\u4e0d\u60f3\u652f\u6301\u7684\u7c7b\u578b\uff09\uff0c\u53ef\u4ee5\u7ed3\u5408\u4f7f\u7528\uff1a<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u901a\u7528\u65b9\u6cd5\uff1a\u4f7f\u7528\u66f4\u7075\u6d3b\u7684\u5224\u65ad\u65b9\u5f0f\n *\/\nfunction add_post_tag_to_all_cpts( $post_type, $args ) {\n    \/\/ \u83b7\u53d6\u6587\u7ae0\u7c7b\u578b\u5bf9\u8c61\n    $post_type_object = get_post_type_object( $post_type );\n\n    \/\/ \u5982\u679c\u6587\u7ae0\u7c7b\u578b\u662f\u5185\u7f6e\u7684\uff0c\u5219\u8df3\u8fc7\n    if ( $post_type_object &amp;&amp; $post_type_object-&gt;_builtin ) {\n        return;\n    }\n\n    \/\/ \u989d\u5916\u6392\u9664\u4e00\u4e9b\u7279\u5b9a\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff08\u5982\u679c\u9700\u8981\uff09\n    $excluded_cpts = array( 'some_plugin_cpt', 'another_cpt' );\n    if ( in_array( $post_type, $excluded_cpts ) ) {\n        return;\n    }\n\n    \/\/ \u4e3a\u8fd9\u4e2a\u65b0\u6ce8\u518c\u7684\u975e\u5185\u7f6eCPT\u6dfb\u52a0post_tag\u652f\u6301\n    register_taxonomy_for_object_type( 'post_tag', $post_type );\n}\nadd_action( 'registered_post_type', 'add_post_tag_to_all_cpts', 10, 2 );<\/code><\/pre><h3 class=\"wp-block-heading\">\u4f7f\u7528WordPress\u6838\u5fc3\u51fd\u6570\u83b7\u53d6\u5185\u7f6e\u7c7b\u578b\u5217\u8868<\/h3><p>\u867d\u7136\u4ecd\u7136\u662f\u4e00\u4e2a\u5217\u8868\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7WordPress\u51fd\u6570\u83b7\u53d6\uff0c\u6bd4\u786c\u7f16\u7801\u7a0d\u597d\uff1a<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u4f7f\u7528 get_post_types() \u83b7\u53d6\u5185\u7f6e\u7c7b\u578b\u5217\u8868\n *\/\nfunction add_post_tag_to_all_cpts( $post_type, $args ) {\n    \/\/ \u83b7\u53d6\u6240\u6709\u5185\u7f6e\u6587\u7ae0\u7c7b\u578b\n    $built_in_post_types = get_post_types( array( '_builtin' =&gt; true ) );\n\n    \/\/ \u5982\u679c\u662f\u5185\u7f6e\u6587\u7ae0\u7c7b\u578b\uff0c\u5219\u8df3\u8fc7\n    if ( in_array( $post_type, $built_in_post_types ) ) {\n        return;\n    }\n\n    \/\/ \u4e3a\u8fd9\u4e2a\u65b0\u6ce8\u518c\u7684CPT\u6dfb\u52a0post_tag\u652f\u6301\n    register_taxonomy_for_object_type( 'post_tag', $post_type );\n}\nadd_action( 'registered_post_type', 'add_post_tag_to_all_cpts', 10, 2 );<\/code><\/pre><h3 class=\"wp-block-heading\">\u5bf9\u6bd4\u603b\u7ed3<\/h3><figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u65b9\u6cd5<\/th><th>\u4f18\u70b9<\/th><th>\u7f3a\u70b9<\/th><\/tr><\/thead><tbody><tr><td><strong>\u786c\u7f16\u7801\u5217\u8868<\/strong><\/td><td>\u7b80\u5355\u76f4\u63a5\uff0c\u6027\u80fd\u597d<\/td><td>\u9700\u8981\u624b\u52a8\u66f4\u65b0\uff0c\u53ef\u80fd\u9057\u6f0f<\/td><\/tr><tr><td><strong>_builtin \u5c5e\u6027<\/strong><\/td><td>\u52a8\u6001\u9002\u5e94\uff0c\u4ee3\u7801\u7b80\u6d01<\/td><td>\u4f9d\u8d56WordPress\u5185\u90e8\u5b9e\u73b0<\/td><\/tr><tr><td><strong>get_post_types()<\/strong><\/td><td>\u76f8\u5bf9\u52a8\u6001\uff0c\u4ee3\u7801\u6e05\u6670<\/td><td>\u6bcf\u6b21\u8c03\u7528\u90fd\u6267\u884c\u67e5\u8be2\uff0c\u6027\u80fd\u7a0d\u5dee<\/td><\/tr><\/tbody><\/table><\/figure><p><strong>\u63a8\u8350\u4f7f\u7528\u65b9\u6cd5<\/strong>\uff08\u57fa\u4e8e <code>_builtin<\/code> \u5c5e\u6027\uff09\uff0c\u56e0\u4e3a\u5b83\u662f\u6700\u7b80\u6d01\u3001\u6700\u9762\u5411\u672a\u6765\u7684\u89e3\u51b3\u65b9\u6848\u3002\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u4f9d\u8d56\u4e8e\u53ef\u80fd\u53d8\u5316\u7684\u786c\u7f16\u7801\u5217\u8868\uff0c\u800c\u662f\u5229\u7528WordPress\u81ea\u8eab\u63d0\u4f9b\u7684\u673a\u5236\u6765\u533a\u5206\u5185\u7f6e\u548c\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u3002<\/p><h2 class=\"wp-block-heading\">\ud83d\udedc \u4f7f\u7528\u540e\u7684\u6548\u679c\u4e0e\u63d0\u793a<\/h2><p>\u65e0\u8bba\u91c7\u7528\u4ee5\u4e0a\u54ea\u79cd\u65b9\u6cd5\uff0c\u6210\u529f\u6dfb\u52a0\u540e\uff0c\u4f60\u5728WordPress\u540e\u53f0\u7f16\u8f91\u4f60\u6307\u5b9a\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u65f6\uff0c\u5e94\u8be5\u5c31\u80fd\u5728\u7f16\u8f91\u5668\u7684\u53f3\u4fa7\uff08\u6216\u5176\u4ed6\u4f4d\u7f6e\uff0c\u53d6\u51b3\u4e8e\u4f60\u7684\u4e3b\u9898\u548c\u7f16\u8f91\u5668\u8bbe\u7f6e\uff09\u770b\u5230\u719f\u6089\u7684<strong>\u6807\u7b7e\u5143\u6846<\/strong>\uff08Tag meta box\uff09\uff0c\u5c31\u50cf\u7f16\u8f91\u666e\u901a\u6587\u7ae0\u65f6\u4e00\u6837\uff0c\u4f60\u53ef\u4ee5\u5728\u8fd9\u91cc\u4e3a\u81ea\u5b9a\u4e49\u6587\u7ae0\u6dfb\u52a0\u548c\u7ba1\u7406\u6807\u7b7e\u3002<\/p><p><strong>\u91cd\u8981\u63d0\u793a<\/strong>\uff1a\u5728\u4fee\u6539\u4e86\u4ee3\u7801\u4e4b\u540e\uff0c\u8bf7\u52a1\u5fc5\u8fdb\u5165WordPress\u540e\u53f0\u7684\u3010\u8bbe\u7f6e\u3011\u2192\u3010\u56fa\u5b9a\u94fe\u63a5\u3011\u9875\u9762\uff0c\u76f4\u63a5\u70b9\u51fb\u3010\u4fdd\u5b58\u66f4\u6539\u3011\u3002<strong>\u65e0\u9700\u505a\u4efb\u4f55\u6539\u52a8<\/strong>\uff0c\u53ea\u9700\u4fdd\u5b58\u4e00\u6b21\u5373\u53ef\u3002\u8fd9\u4e00\u6b65\u64cd\u4f5c\u4f1a\u5237\u65b0WordPress\u7684\u91cd\u5199\u89c4\u5219\uff08Rewrite Rules\uff09\uff0c\u786e\u4fdd\u4f60\u7684\u6807\u7b7e\u5f52\u6863\u9875\u9762\uff08\u5982 <code>\/tag\/tag-name\/<\/code>\uff09\u80fd\u591f\u6b63\u786e\u5730\u663e\u793a\u6765\u81ea\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u5185\u5bb9\u3002<\/p><h2 class=\"wp-block-heading\">\ud83c\udfaf \u5982\u4f55\u9009\u62e9\u4e0e\u64cd\u4f5c\u5efa\u8bae<\/h2><ol class=\"wp-block-list\">\n<li><strong>\u660e\u786e\u77e5\u9053CPT\u540d\u79f0\uff0c\u53ea\u4e3a\u7279\u5b9aCPT\u6dfb\u52a0<\/strong>\uff1a\u4f7f\u7528\u65b9\u6cd5\u4e8c\uff0c\u5c06\u4ee3\u7801\u4e2d\u7684 <code>my_existing_cpt<\/code> \u66ff\u6362\u6210\u4f60\u5b9e\u9645\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\uff08\u5982 <code>product<\/code>, <code>movie<\/code>, <code>book<\/code> \u7b49\uff09\u3002<\/li>\n\n\n\n<li><strong>\u60f3\u4e00\u52b3\u6c38\u9038\uff0c\u4e3a\u65b0\u65e7CPT\u90fd\u9ed8\u8ba4\u6dfb\u52a0<\/strong>\uff1a\u4f7f\u7528\u65b9\u6cd5\u4e09\u3002\u8fd9\u662f\u6700\u7701\u4e8b\u7684\u65b9\u6cd5\uff0c\u5c24\u5176\u9002\u7528\u4e8e\u90a3\u4e9b\u4f7f\u7528\u4e86\u5927\u91cf\u7b2c\u4e09\u65b9\u63d2\u4ef6\uff08\u5b83\u4eec\u4f1a\u6ce8\u518c\u81ea\u5df1\u7684CPT\uff09\u7684\u7f51\u7ad9\u3002<\/li>\n\n\n\n<li><strong>\u521b\u5efa\u65b0\u7684CPT\u65f6<\/strong>\uff1a\u4f7f\u7528\u65b9\u6cd5\u4e00\uff0c\u5728\u6ce8\u518c\u4ee3\u7801\u91cc\u76f4\u63a5\u5199\u597d\u662f\u6700\u89c4\u8303\u7684\u3002<\/li>\n<\/ol><p><strong>\u64cd\u4f5c\u6b65\u9aa4<\/strong>\uff1a<\/p><ol class=\"wp-block-list\">\n<li>\u5c06\u4f60\u9009\u62e9\u7684\u4ee3\u7801\u7247\u6bb5\u6dfb\u52a0\u5230\u5f53\u524d\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\u672b\u5c3e\uff0c\u6216\u8005\u6dfb\u52a0\u5230\u4f60\u7684\u81ea\u5b9a\u4e49\u529f\u80fd\u63d2\u4ef6\u4e2d\u3002<\/li>\n\n\n\n<li>\u4fdd\u5b58\u6587\u4ef6\u3002<\/li>\n\n\n\n<li>\u767b\u5f55WordPress\u540e\u53f0\uff0c\u5237\u65b0\u56fa\u5b9a\u94fe\u63a5\u8bbe\u7f6e\uff08\u3010\u8bbe\u7f6e\u3011\u2192\u3010\u56fa\u5b9a\u94fe\u63a5\u3011\u2192\u76f4\u63a5\u70b9\u51fb\u3010\u4fdd\u5b58\u66f4\u6539\u3011\uff09\u3002<\/li>\n\n\n\n<li>\u53bb\u7f16\u8f91\u4f60\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\uff0c\u68c0\u67e5\u6807\u7b7e\u6846\u662f\u5426\u51fa\u73b0\u3002<\/li>\n<\/ol>","protected":false},"excerpt":{"rendered":"<p>\u5c06WordPress\u9ed8\u8ba4\u7684\u201c\u6807\u7b7e\u201d\uff08post_tag\uff09\u5206\u7c7b\u6cd5\u6dfb\u52a0\u5230\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff08CPT\uff09\u4e0a\uff0c\u662f\u4e00\u4e2a\u5e38\u89c1\u4e14\u5b9e\u7528\u7684\u9700\u6c42\u3002\u65e0\u8bba\u662f\u5df2\u7ecf\u521b\u5efa\u8fd8\u662f\u672a\u6765\u5c06\u8981\u521b\u5efa\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff0c\u90fd\u6709\u76f8\u5e94\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002 \u65b9\u6cd5\u4e00\uff1a\u6ce8\u518c\u65b0\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u65f6\u76f4\u63a5\u6dfb\u52a0 \u5982\u679c\u4f60\u5c1a\u672a\u521b\u5efa\u6216\u6b63\u5728\u521b\u5efa\u65b0\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff0c\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u5728 register_post_t..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":true},"tags":[49,2107,50],"bjjc2nav":[34],"tuisongtax":[],"class_list":["post-4739","bjjc","type-bjjc","status-publish","hentry","tag-rmzn","tag-cjyy","tag-xsbdtj","bjjc2nav-wptspz"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"\u4e3a\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u6dfb\u52a0\u6807\u7b7e","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":"\u4e3a\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u6dfb\u52a0\u6807\u7b7e"}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc\/4739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/bjjc"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=4739"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=4739"},{"taxonomy":"bjjc2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc2nav?post=4739"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=4739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}