{"id":4314,"date":"2025-07-31T11:31:00","date_gmt":"2025-07-31T03:31:00","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4314.html"},"modified":"2025-12-11T10:34:10","modified_gmt":"2025-12-11T02:34:10","slug":"%e7%bb%9f%e8%ae%a1wordpress%e8%87%aa%e5%ae%9a%e4%b9%89%e6%96%87%e7%ab%a0%e7%b1%bb%e5%9e%8b%e5%b7%b2%e5%8f%91%e5%b8%83%e6%96%87%e7%ab%a0%e6%95%b0%e9%87%8f%ef%bc%8c%e5%ae%9e%e6%97%b6%e8%8e%b7%e5%8f%96","status":"publish","type":"bjjc","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4314.html","title":{"rendered":"\u5b9e\u65f6\u7edf\u8ba1WordPress\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u5df2\u53d1\u5e03\u6587\u7ae0\u6570\u91cf\uff0c\u4e0e\u83b7\u53d6\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u96c6"},"content":{"rendered":"<p>\u6211\u4eec\u5df2\u5c06\u5b9e\u65f6\u7edf\u8ba1WordPress\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u5df2\u53d1\u5e03\u6587\u7ae0\u6570\u91cf\uff0c\u4e0e\u83b7\u53d6\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u96c6\u4e24\u90e8\u5206\u5408\u5e76\u5230\u4e00\u8d77\u3002<\/p><p>\u5373\u4fbf\u662f\u4f60\u7528\u5230\u63d2\u4ef6\u540e\uff0c\u8bb0\u5f55\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u5df2\u53d1\u5e03\u6587\u7ae0\u6570\u91cf\u4f1a\u8ddf\u7740\u4f60\u65b0\u53d1\u5e03\u6216\u5220\u9664\u6587\u7ae0\u81ea\u52a8\u589e\u51cf\uff0c\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u96c6\u4e5f\u4f1a\u8bb2\u65b0\u521b\u5efa\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7edf\u8ba1\u5728\u5185\uff0c\u4ee3\u7801\u5b9e\u73b0\u4e86\u7cfb\u7edf\u5b9e\u65f6\u83b7\u53d6\u3002<\/p><h2 class=\"wp-block-heading\">\u4ee3\u7801<\/h2><pre class=\"wp-block-code\"><code>\n\/\/=================================\u7b2c\u4e00\u90e8\u5206===========================================\n\/\/ 1.\u5148\u6302\u597d\u94a9\u5b50\n\/\/\u83b7\u53d6posttype\u9891\u9053\u7684\u5df2\u53d1\u5e03\u6587\u7ae0\u7684\u603b\u6570\u91cf\u65b9\u6cd5\n\/\/ \u5728 init \u94a9\u5b50\u4e2d\u5904\u7406\u7edf\u8ba1:\u5904\u7406\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u603b\u6570\u91cf\nadd_action('init', 'zzw_static_count_custom_post_types', 99); \/\/ \u4f18\u5148\u7ea799\u786e\u4fdd\u6700\u540e\u6267\u884c\nfunction zzw_static_count_custom_post_types() {\n    if (!get_option('zzw_static_needs_cpt_count')) return;\n\n    $args = array(\n        'public'   =&gt; true,\n        '_builtin' =&gt; false\n    );\n    $post_types = get_post_types($args, 'names', 'and');\n    \n    foreach ($post_types as $post_type) {\n        $count = (string) wp_count_posts($post_type)-&gt;publish;\n        update_option( 'DIY name1', $count);\n\n    }\n    $post_types_string = implode(\",\", $post_types);\n    $post_types_string = $post_types_string.',post';\n    $post_types_string = $post_types_string.',page';\n    update_option( 'DIY name2', $post_types_string);;\/\/\u5168\u90e8posttype\u540d\u79f0\u4ee5\u201c,\u201d\u5206\u9694\u7684\u5b57\u7b26\u4e32\n\n    \n    delete_option('zzw_static_needs_cpt_count'); \/\/ \u6e05\u9664\u6807\u8bb0\n}\n\n\/\/ 2.\u5728\u4f60\u7684\u76ee\u6807\u51fd\u6570\u6216\u5176\u4ed6\u4f4d\u7f6e\uff0c\u5b9a\u4e49\u6fc0\u6d3b\u6807\u8bb0\n\/\/ update_option('zzw_static_needs_cpt_count', true);\n\n\n\/\/=================================\u7b2c\u4e8c\u90e8\u5206===========================================\n\n\/\/ \u65b0\u5efa\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u5b9e\u65f6\u54cd\u5e94\u6587\u7ae0\u603b\u6570\u91cf\nadd_action('registered_post_type', function($post_type, $args) {\n\n    \/\/\u8fc7\u6ee4\u6389\u975e\u516c\u5f00\u6216\u4e3a\u5185\u7f6e\u7684posttype\u7c7b\u578b\n    if (!$args-&gt;public || $args-&gt;_builtin) return;\n    \n    \/\/\u4e3a\u65b0\u5efaposttype\u589e\u8bbe_{$post_type}_zongshu\u5b57\u6bb5\uff0c\u5e76\u8d4b\u503c\u6587\u7ae0\u603b\u6570\n    $count = (string) wp_count_posts($post_type)-&gt;publish;\n    update_option( 'DIY name1', $count);\n\n    \/\/\u8c03\u6574_pts_string\u5b57\u6bb5\u503c\uff0c\u5c06\u7b26\u5408\u6761\u4ef6\u5e76\u672a\u88ab\u5217\u5165\u7684posttype\u52a0\u5165\u5230\u8be5\u5b57\u6bb5\u503c\u4e2d\n    $s_pts_string = get_option('DIY name');\n    if ( strpos($s_pts_string, $post_type) === false ) {\n        $s_pts_string = $post_type.','.$s_pts_string;\n    }\n    update_option( 'DIY name2', $s_pts_string);\n\n}, 10, 2);\n\n\n\n\n\/\/=================================\u7b2c\u4e09\u90e8\u5206===========================================\n\n\/\/ \u6587\u7ae0\u53d8\u66f4\uff08\u53d1\u5e03\u5df2\u53d1\u5e03\/\u53d8\u66f4\u72b6\u6001\u4e3a\u975e\u5df2\u53d1\u5e03\uff09\u589e\u91cf\u66f4\u65b0\n\/\/ \u5728\u6587\u7ae0\u4fdd\u5b58\u524d\u6355\u83b7\u65e7\u72b6\u6001\nadd_action('pre_post_update', function($post_id) {\n    if ($post = get_post($post_id)) {\n        $GLOBALS['zzw_old_post_status'] = $post-&gt;post_status;\n    }\n});\n\n\/\/ \u4e3b\u5904\u7406\u903b\u8f91\nadd_action('save_post', function($post_id, $post) {\n    \/\/ \u6392\u9664\u4fee\u8ba2\u7248\u548c\u81ea\u52a8\u4fdd\u5b58\n    if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {\n        return;\n    }\n    \n    \/\/ \u83b7\u53d6\u53d8\u66f4\u524d\u7684\u72b6\u6001\n    $old_status = $GLOBALS['zzw_old_post_status'] ?? '';\n    $new_status = $post-&gt;post_status;\n    \n    \/\/ \u8c03\u8bd5\u65e5\u5fd7\uff08\u751f\u4ea7\u73af\u5883\u53ef\u79fb\u9664\uff09\n    \/\/ error_log(\"Post {$post_id} status change: {$old_status} =&gt; {$new_status}\");\n    \n    \/\/ \u53ea\u5904\u7406\u5b9e\u9645\u72b6\u6001\u53d8\u66f4\n    if ($old_status === $new_status) {\n        return;\n    }\n    \n    $current_count = (int) get_option('DIY name1');\n    \n    \/\/ \u53d1\u5e03\u6587\u7ae0\uff08\u4ece\u975e\u53d1\u5e03\u72b6\u6001\u53d8\u4e3a\u53d1\u5e03\u72b6\u6001\uff09\n    if ('publish' === $new_status &amp;&amp; 'publish' !== $old_status) {\n        update_option( 'DIY name1', ($current_count+1) );\n        \/\/ error_log(\"ID\u4e3a {$post_id} \u7684\u6587\u7ae0\u53d1\u5e03\u6216\u66f4\u6539\u4e3a\u4e86\u53d1\u5e03\u72b6\u6001\uff0c\u8be5\u9891\u9053\u6587\u7ae0\u603b\u6570\u8bb0\u5f55\u5b57\u6bb5 {$log_name} \u52a01\u6210\u529f\");\n    }\n    \/\/ \u53d6\u6d88\u53d1\u5e03\uff08\u4ece\u53d1\u5e03\u72b6\u6001\u53d8\u4e3a\u975e\u53d1\u5e03\u72b6\u6001\uff09\n    elseif ('publish' !== $new_status &amp;&amp; 'publish' === $old_status) {\n        update_option( 'DIY name1', ($current_count-1) );\n        \/\/ error_log(\"ID\u4e3a {$post_id} \u7684\u6587\u7ae0\u72b6\u6001\u53d8\u66f4\u4e3a\u4e86\u975e\u53d1\u5e03\u72b6\u6001\uff0c\u8be5\u9891\u9053\u6587\u7ae0\u603b\u6570\u8bb0\u5f55\u5b57\u6bb5 {$log_name} \u51cf1\u6210\u529f\");\n    }\n}, 10, 2);<\/code><\/pre><p>\u4f7f\u7528\uff1a<\/p><p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>\u4ee3\u7801\u4f7f\u7528\u91cd\u70b9\u6ce8\u610f\uff1a\u5c06\u4ee3\u7801\u4e2d\u7684 \u201cDIY name\u201d \u66ff\u6362\u4e3a\u4f60\u7684\u81ea\u5b9a\u4e49\u5b57\u6bb5\u540d\u3002<\/strong><\/mark>\u56e0\u4e3a\u8fd9\u6bb5\u4ee3\u7801\u7684\u5b9e\u73b0\u76ee\u7684\u662f\u5b58\u50a8\u76ee\u6807\u6570\u636e\uff0c\u65b9\u4fbf\u4f7f\u7528\u65f6\u8c03\u53d6\u3002<\/p><p>\u5728\u4f60\u7684\u76ee\u6807\u51fd\u6570\u6216\u5176\u4ed6\u4f4d\u7f6e\uff0c\u5b9a\u4e49\u6fc0\u6d3b\u6807\u8bb0<\/p><pre class=\"wp-block-code\"><code>\/\/ 2.\u5728\u4f60\u7684\u76ee\u6807\u51fd\u6570\u6216\u5176\u4ed6\u4f4d\u7f6e\uff0c\u5b9a\u4e49\u6fc0\u6d3b\u6807\u8bb0\nupdate_option('zzw_static_needs_cpt_count', true);<\/code><\/pre><h2 class=\"wp-block-heading\">\u8be6\u89e3<\/h2><p>\u4ee5\u4e0b\u662f\u5bf9\u60a8\u63d0\u4f9b\u7684\u4ee3\u7801\u7684\u8be6\u7ec6\u89e3\u6790\uff0c\u5206\u4e3a\u4e09\u4e2a\u4e3b\u8981\u90e8\u5206\uff1a<\/p><h3 class=\"wp-block-heading\">\u7b2c\u4e00\u90e8\u5206\uff1a\u521d\u59cb\u5316\u7edf\u8ba1\uff08\u6279\u91cf\u66f4\u65b0\uff09<\/h3><pre class=\"wp-block-code\"><code>\/\/ 1. \u5728 init \u94a9\u5b50\u4e2d\u5904\u7406\u7edf\u8ba1\nadd_action('init', 'zzw_static_count_custom_post_types', 99);\nfunction zzw_static_count_custom_post_types() {\n    \/\/ \u68c0\u67e5\u662f\u5426\u9700\u8981\u6267\u884c\u7edf\u8ba1\n    if (!get_option('zzw_static_needs_cpt_count')) return;\n\n    \/\/ \u83b7\u53d6\u6240\u6709\u516c\u5f00\u7684\u975e\u5185\u7f6e\u6587\u7ae0\u7c7b\u578b\n    $args = array(\n        'public'   =&gt; true,\n        '_builtin' =&gt; false\n    );\n    $post_types = get_post_types($args, 'names', 'and');\n\n    \/\/ \u904d\u5386\u5904\u7406\u6bcf\u4e2a\u6587\u7ae0\u7c7b\u578b\n    foreach ($post_types as $post_type) {\n        \/\/ \u83b7\u53d6\u5df2\u53d1\u5e03\u6587\u7ae0\u6570\u91cf\n        $count = (string) wp_count_posts($post_type)-&gt;publish;\n        \/\/ \u66f4\u65b0\u6587\u7ae0\u603b\u6570\u9009\u9879\uff08\u26a0\ufe0f \u6ce8\u610f\uff1a\u8fd9\u91cc\u4f1a\u8986\u76d6\u524d\u503c\uff09\n        update_option( 'DIY name1', $count);\n    }\n\n    \/\/ \u6784\u5efa\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u5b57\u7b26\u4e32\n    $post_types_string = implode(\",\", $post_types);\n    $post_types_string = $post_types_string.',post'; \/\/ \u6dfb\u52a0\u6587\u7ae0\u7c7b\u578b\n    $post_types_string = $post_types_string.',page'; \/\/ \u6dfb\u52a0\u9875\u9762\u7c7b\u578b\n    \/\/ \u5b58\u50a8\u6587\u7ae0\u7c7b\u578b\u5217\u8868\n    update_option( 'DIY name2', $post_types_string);\n\n    \/\/ \u6e05\u9664\u6267\u884c\u6807\u8bb0\n    delete_option('zzw_static_needs_cpt_count');\n}\n\n\/\/ 2. \u89e6\u53d1\u7edf\u8ba1\u7684\u6fc0\u6d3b\u65b9\u5f0f\uff08\u793a\u4f8b\uff09\n\/\/ update_option('zzw_static_needs_cpt_count', true);<\/code><\/pre><p><strong>\u529f\u80fd\u8bf4\u660e\uff1a<\/strong><\/p><ol class=\"wp-block-list\">\n<li>\u901a\u8fc7 <code>zzw_static_needs_cpt_count<\/code> \u9009\u9879\u63a7\u5236\u6267\u884c<\/li>\n\n\n\n<li>\u83b7\u53d6\u6240\u6709 <strong>\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b<\/strong>\uff08\u975e\u5185\u7f6e+\u516c\u5f00\uff09<\/li>\n\n\n\n<li>\u904d\u5386\u66f4\u65b0\u6587\u7ae0\u603b\u6570\u5230 <code>DIY name1<\/code>\uff08\u26a0\ufe0f \u5faa\u73af\u5185\u4f1a\u8986\u76d6\u524d\u503c\uff09<\/li>\n\n\n\n<li>\u6784\u5efa\u5305\u542b\u6240\u6709\u6587\u7ae0\u7c7b\u578b\u7684\u5b57\u7b26\u4e32\uff08\u81ea\u5b9a\u4e49+post+page\uff09\u5b58\u5230 <code>DIY name2<\/code><\/li>\n\n\n\n<li>\u9700\u8981\u624b\u52a8\u6fc0\u6d3b\uff1a<code>update_option('zzw_static_needs_cpt_count', true)<\/code><\/li>\n<\/ol><p><strong>\u5b58\u5728\u95ee\u9898\uff1a<\/strong><\/p><ul class=\"wp-block-list\">\n<li><code>DIY name1<\/code> \u5728\u5faa\u73af\u4e2d\u88ab\u591a\u6b21\u8986\u76d6\uff0c\u6700\u7ec8\u53ea\u5b58\u50a8\u6700\u540e\u4e00\u79cd\u6587\u7ae0\u7c7b\u578b\u7684\u6570\u91cf<\/li>\n\n\n\n<li>\u672a\u7edf\u8ba1\u5185\u7f6e\u7684 post\/page \u6587\u7ae0\u6570\u91cf<\/li>\n\n\n\n<li>\u6bcf\u6b21\u6fc0\u6d3b\u4f1a\u5b8c\u5168\u91cd\u7f6e\u6570\u636e<\/li>\n<\/ul><hr class=\"wp-block-separator has-alpha-channel-opacity\"><h3 class=\"wp-block-heading\">\u7b2c\u4e8c\u90e8\u5206\uff1a\u65b0\u5efa\u6587\u7ae0\u7c7b\u578b\u5b9e\u65f6\u54cd\u5e94<\/h3><pre class=\"wp-block-code\"><code>add_action('registered_post_type', function($post_type, $args) {\n    \/\/ \u53ea\u5904\u7406\u516c\u5f00\u7684\u975e\u5185\u7f6e\u7c7b\u578b\n    if (!$args-&gt;public || $args-&gt;_builtin) return;\n\n    \/\/ \u83b7\u53d6\u65b0\u7c7b\u578b\u7684\u6587\u7ae0\u6570\u91cf\n    $count = (string) wp_count_posts($post_type)-&gt;publish;\n    \/\/ \u66f4\u65b0\u603b\u6570\uff08\u26a0\ufe0f \u8986\u76d6\u73b0\u6709\u503c\uff09\n    update_option( 'DIY name1', $count);\n\n    \/\/ \u83b7\u53d6\u73b0\u6709\u7c7b\u578b\u5b57\u7b26\u4e32\n    $s_pts_string = get_option('DIY name2');\n    \/\/ \u6dfb\u52a0\u65b0\u7c7b\u578b\uff08\u5982\u679c\u4e0d\u5b58\u5728\uff09\n    if ( strpos($s_pts_string, $post_type) === false ) {\n        $s_pts_string = $post_type.','.$s_pts_string;\n    }\n    \/\/ \u66f4\u65b0\u7c7b\u578b\u5217\u8868\n    update_option( 'DIY name2', $s_pts_string);\n}, 10, 2);<\/code><\/pre><p><strong>\u529f\u80fd\u8bf4\u660e\uff1a<\/strong><\/p><ol class=\"wp-block-list\">\n<li>\u5728\u6587\u7ae0\u7c7b\u578b\u6ce8\u518c\u65f6\u89e6\u53d1\uff08<code>registered_post_type<\/code>\uff09<\/li>\n\n\n\n<li>\u66f4\u65b0 <code>DIY name1<\/code> \u4e3a\u65b0\u7c7b\u578b\u7684\u6587\u7ae0\u6570\u91cf\uff08\u26a0\ufe0f \u8986\u76d6\u65e7\u503c\uff09<\/li>\n\n\n\n<li>\u5c06\u65b0\u7c7b\u578b\u6dfb\u52a0\u5230 <code>DIY name2<\/code> \u5b57\u7b26\u4e32\u5f00\u5934<\/li>\n<\/ol><p><strong>\u5b58\u5728\u95ee\u9898\uff1a<\/strong><\/p><ul class=\"wp-block-list\">\n<li><code>DIY name1<\/code> \u88ab\u8986\u76d6\uff0c\u4e22\u5931\u4e4b\u524d\u5b58\u50a8\u7684\u7edf\u8ba1<\/li>\n\n\n\n<li>\u672a\u8003\u8651\u65b0\u7c7b\u578b\u53ef\u80fd\u5df2\u6709\u6587\u7ae0\u7684\u60c5\u51b5<\/li>\n\n\n\n<li>\u6dfb\u52a0\u903b\u8f91\u4f1a\u4f7f\u7c7b\u578b\u5217\u8868\u987a\u5e8f\u6df7\u4e71\uff08\u65b0\u7c7b\u578b\u52a0\u5728\u5f00\u5934\uff09<\/li>\n<\/ul><hr class=\"wp-block-separator has-alpha-channel-opacity\"><h3 class=\"wp-block-heading\">\u7b2c\u4e09\u90e8\u5206\uff1a\u6587\u7ae0\u72b6\u6001\u53d8\u66f4\u5904\u7406<\/h3><pre class=\"wp-block-code\"><code>\/\/ \u6355\u83b7\u66f4\u65b0\u524d\u7684\u72b6\u6001\nadd_action('pre_post_update', function($post_id) {\n    if ($post = get_post($post_id)) {\n        $GLOBALS['zzw_old_post_status'] = $post-&gt;post_status;\n    }\n});\n\n\/\/ \u4e3b\u5904\u7406\u903b\u8f91\nadd_action('save_post', function($post_id, $post) {\n    \/\/ \u6392\u9664\u65e0\u6548\u4fdd\u5b58\n    if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) return;\n\n    \/\/ \u83b7\u53d6\u72b6\u6001\u53d8\u5316\n    $old_status = $GLOBALS['zzw_old_post_status'] ?? '';\n    $new_status = $post-&gt;post_status;\n\n    \/\/ \u5ffd\u7565\u672a\u53d8\u5316\u7684\u72b6\u6001\n    if ($old_status === $new_status) return;\n\n    \/\/ \u83b7\u53d6\u5f53\u524d\u603b\u6570\n    $current_count = (int) get_option('DIY name1');\n\n    \/\/ \u53d1\u5e03\u6587\u7ae0\uff1a\u975e\u53d1\u5e03 \u2192 \u53d1\u5e03\n    if ('publish' === $new_status &amp;&amp; 'publish' !== $old_status) {\n        update_option( 'DIY name1', ($current_count+1) );\n    }\n    \/\/ \u53d6\u6d88\u53d1\u5e03\uff1a\u53d1\u5e03 \u2192 \u975e\u53d1\u5e03\n    elseif ('publish' !== $new_status &amp;&amp; 'publish' === $old_status) {\n        update_option( 'DIY name1', ($current_count-1) );\n    }\n}, 10, 2);<\/code><\/pre><p><strong>\u529f\u80fd\u8bf4\u660e\uff1a<\/strong><\/p><ol class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>pre_post_update<\/code> \u6355\u83b7\u65e7\u72b6\u6001<\/li>\n\n\n\n<li>\u901a\u8fc7 <code>save_post<\/code> \u5904\u7406\u5b9e\u9645\u72b6\u6001\u53d8\u66f4<\/li>\n\n\n\n<li>\u7cbe\u786e\u8bc6\u522b\u4e24\u79cd\u53d8\u5316\uff1a<\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li>\u65b0\u53d1\u5e03\uff1a\u975e\u53d1\u5e03 \u2192 \u53d1\u5e03\uff08\u603b\u6570+1\uff09<\/li>\n\n\n\n<li>\u53d6\u6d88\u53d1\u5e03\uff1a\u53d1\u5e03 \u2192 \u975e\u53d1\u5e03\uff08\u603b\u6570-1\uff09<\/li>\n<\/ul><ol class=\"wp-block-list\">\n<li>\u6392\u9664\u4fee\u8ba2\u7248\u548c\u81ea\u52a8\u4fdd\u5b58<\/li>\n<\/ol><p><strong>\u4f18\u52bf\uff1a<\/strong><\/p><ul class=\"wp-block-list\">\n<li>\u589e\u91cf\u66f4\u65b0\u6548\u7387\u9ad8<\/li>\n\n\n\n<li>\u72b6\u6001\u53d8\u5316\u5224\u65ad\u7cbe\u51c6<\/li>\n\n\n\n<li>\u907f\u514d\u91cd\u590d\u8ba1\u6570<\/li>\n<\/ul><hr class=\"wp-block-separator has-alpha-channel-opacity\"><h2 class=\"wp-block-heading\">\u4fee\u6539\u6216\u6539\u8fdb\u65b9\u5411<\/h2><ol class=\"wp-block-list\">\n<li><strong>\u6570\u636e\u8986\u76d6\u95ee\u9898<\/strong><\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li>\u7b2c\u4e00\u90e8\u5206\u548c\u7b2c\u4e8c\u90e8\u5206\u90fd\u4f1a\u8986\u76d6 <code>DIY name1<\/code> \u7684\u503c<\/li>\n\n\n\n<li>\u5bfc\u81f4\u6700\u7ec8\u53ea\u5b58\u50a8\u6700\u540e\u5904\u7406\u7684\u6587\u7ae0\u7c7b\u578b\u6570\u91cf<\/li>\n<\/ul><ol class=\"wp-block-list\">\n<li><strong>\u7edf\u8ba1\u4e0d\u5b8c\u6574<\/strong><\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li>\u672a\u7edf\u8ba1\u5185\u7f6e\u7684 post\/page \u6587\u7ae0\u6570\u91cf\uff08\u7b2c\u4e00\u90e8\u5206\uff09<\/li>\n\n\n\n<li>\u5faa\u73af\u5185\u8986\u76d6\u503c\u5bfc\u81f4\u81ea\u5b9a\u4e49\u7c7b\u578b\u7edf\u8ba1\u4e0d\u5168<\/li>\n<\/ul><ol class=\"wp-block-list\">\n<li><strong>\u8bbe\u8ba1\u903b\u8f91\u51b2\u7a81<\/strong><\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li>\u7b2c\u4e00\u90e8\u5206\uff1a\u6279\u91cf\u7edf\u8ba1\u6240\u6709\u7c7b\u578b<\/li>\n\n\n\n<li>\u7b2c\u4e8c\u90e8\u5206\uff1a\u6309\u7c7b\u578b\u5355\u72ec\u5b58\u50a8<\/li>\n\n\n\n<li>\u7b2c\u4e09\u90e8\u5206\uff1a\u5047\u8bbe\u5b58\u50a8\u5168\u5c40\u603b\u6570<\/li>\n<\/ul><ol class=\"wp-block-list\">\n<li><strong>\u7c7b\u578b\u5217\u8868\u7ba1\u7406<\/strong><\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li>\u6dfb\u52a0\u65b0\u7c7b\u578b\u65f6\u76f4\u63a5\u4fee\u6539\u5b57\u7b26\u4e32<\/li>\n\n\n\n<li>\u7f3a\u4e4f\u552f\u4e00\u6027\u68c0\u67e5\u548c\u683c\u5f0f\u63a7\u5236<\/li>\n<\/ul><hr class=\"wp-block-separator has-alpha-channel-opacity\"><h2 class=\"wp-block-heading\">\u6539\u8fdb\u5efa\u8bae<\/h2><ol class=\"wp-block-list\">\n<li><strong>\u6570\u636e\u7ed3\u6784\u4f18\u5316<\/strong><br>\u4f7f\u7528\u6570\u7ec4\u5b58\u50a8\u6570\u636e\uff1a<\/li>\n<\/ol><pre class=\"wp-block-code\"><code>   \/\/ \u603b\u6570\u5b58\u50a8\n   update_option('zzw_total_count', [\n       'post' =&gt; 120,\n       'product' =&gt; 85,\n       'total' =&gt; 205\n   ]);\n\n   \/\/ \u7c7b\u578b\u5217\u8868\u5b58\u50a8\n   update_option('zzw_post_types', ['post', 'page', 'product']);<\/code><\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u7b2c\u4e00\u90e8\u5206\u4fee\u6b63<\/strong><\/li>\n<\/ol><pre class=\"wp-block-code\"><code>   $total_count = 0;\n   $all_types = [];\n\n   \/\/ \u7edf\u8ba1\u81ea\u5b9a\u4e49\u7c7b\u578b\n   foreach ($custom_types as $type) {\n       $count = wp_count_posts($type)-&gt;publish;\n       $total_count += $count;\n       $all_types[] = $type;\n   }\n\n   \/\/ \u6dfb\u52a0\u5185\u7f6e\u7c7b\u578b\n   $post_count = wp_count_posts('post')-&gt;publish;\n   $page_count = wp_count_posts('page')-&gt;publish;\n   $total_count += $post_count + $page_count;\n\n   $all_types = array_merge($all_types, ['post', 'page']);<\/code><\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u7b2c\u4e8c\u90e8\u5206\u4fee\u6b63<\/strong><\/li>\n<\/ol><pre class=\"wp-block-code\"><code>   \/\/ \u83b7\u53d6\u73b0\u6709\u6570\u636e\n   $total_data = get_option('zzw_total_count');\n   $type_list = get_option('zzw_post_types');\n\n   \/\/ \u6dfb\u52a0\u65b0\u7c7b\u578b\n   if (!in_array($post_type, $type_list)) {\n       $count = wp_count_posts($post_type)-&gt;publish;\n       $total_data[$post_type] = $count;\n       $total_data['total'] += $count;\n       $type_list[] = $post_type;\n   }<\/code><\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li><strong>\u7b2c\u4e09\u90e8\u5206\u589e\u5f3a<\/strong><\/li>\n<\/ol><pre class=\"wp-block-code\"><code>   \/\/ \u5728\u72b6\u6001\u53d8\u66f4\u5904\u7406\u4e2d\n   $post_type = $post-&gt;post_type;\n   $total_data = get_option('zzw_total_count');\n\n   if ($status_change === 'published') {\n       $total_data[$post_type]++;\n       $total_data['total']++;\n   }<\/code><\/pre><blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5173\u952e\u6539\u8fdb\u65b9\u5411\uff1a\u4f7f\u7528\u7ed3\u6784\u5316\u6570\u636e\u5b58\u50a8\u3001\u533a\u5206\u7c7b\u578b\u7edf\u8ba1\u3001\u7ef4\u62a4\u5168\u5c40\u603b\u6570\u3001\u589e\u52a0\u7f13\u5b58\u673a\u5236\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u5df2\u5c06\u5b9e\u65f6\u7edf\u8ba1WordPress\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u5df2\u53d1\u5e03\u6587\u7ae0\u6570\u91cf\uff0c\u4e0e\u83b7\u53d6\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u96c6\u4e24\u90e8\u5206\u5408\u5e76\u5230\u4e00\u8d77\u3002 \u5373\u4fbf\u662f\u4f60\u7528\u5230\u63d2\u4ef6\u540e\uff0c\u8bb0\u5f55\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u5df2\u53d1\u5e03\u6587\u7ae0\u6570\u91cf\u4f1a\u8ddf\u7740\u4f60\u65b0\u53d1\u5e03\u6216\u5220\u9664\u6587\u7ae0\u81ea\u52a8\u589e\u51cf\uff0c\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u96c6\u4e5f\u4f1a\u8bb2\u65b0\u521b\u5efa\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7edf\u8ba1\u5728\u5185\uff0c\u4ee3\u7801\u5b9e\u73b0\u4e86\u7cfb\u7edf\u5b9e\u65f6\u83b7\u53d6\u3002 \u4ee3\u7801 \u4f7f\u7528\uff1a \u4ee3\u7801\u4f7f\u7528\u91cd\u70b9\u6ce8\u610f\uff1a\u5c06\u4ee3\u7801..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":true},"tags":[3221,3220],"bjjc2nav":[34],"tuisongtax":[],"class_list":["post-4314","bjjc","type-bjjc","status-publish","hentry","tag-sstjdsxff","tag-wzsltjff","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":"\u7edf\u8ba1\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u6570\u91cf\uff0c\u53ca\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u96c6","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":"\u7edf\u8ba1\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u6570\u91cf\uff0c\u53ca\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u96c6"}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc\/4314","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=4314"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=4314"},{"taxonomy":"bjjc2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc2nav?post=4314"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=4314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}