{"id":4713,"date":"2025-10-20T10:15:40","date_gmt":"2025-10-20T02:15:40","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4713.html"},"modified":"2025-10-20T10:18:09","modified_gmt":"2025-10-20T02:18:09","slug":"wordpress%e6%a0%87%e7%ad%be%e5%88%86%e7%b1%bb%e5%85%b3%e8%81%94%e8%87%aa%e5%ae%9a%e4%b9%89%e6%96%87%e7%ab%a0%e7%b1%bb%e5%9e%8b%ef%bc%8c%e5%b9%b6%e6%98%be%e7%a4%ba%e6%89%80%e6%8c%82%e8%bd%bd%e6%a0%87","status":"publish","type":"bjjc","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4713.html","title":{"rendered":"WordPress\u6807\u7b7e\u5206\u7c7b\u5173\u8054\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff0c\u5e76\u663e\u793a\u6240\u6302\u8f7d\u6807\u7b7e\u5206\u7c7b\u6cd5\u7684\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0"},"content":{"rendered":"<p>\u8fd9\u4e2a\u95ee\u9898\u786e\u5b9e\u5f88\u5e38\u89c1\uff0c\u4f60\u9047\u5230\u7684\u60c5\u51b5\u662f\uff1a\u867d\u7136\u4ece\u5185\u5bb9\u7ba1\u7406\u7684\u89d2\u5ea6\u770b\uff0c\u6807\u7b7e\u5df2\u7ecf\u5173\u8054\u4e86\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff0c\u4f46\u5728\u524d\u53f0\u663e\u793a\u65f6\uff0cWordPress\u7684\u9ed8\u8ba4\u67e5\u8be2\u903b\u8f91\u5e76\u6ca1\u6709\u81ea\u52a8\u5305\u542b\u5b83\u4eec\u3002<\/p><h2 class=\"wp-block-heading\">\u95ee\u9898\u6839\u6e90\uff1a\u9ed8\u8ba4\u67e5\u8be2\u7684\u9650\u5236<\/h2><p>WordPress\u7684\u6807\u7b7e\u5b58\u6863\u9875\u9ed8\u8ba4\u53ea\u67e5\u8be2\u7cfb\u7edf\u9ed8\u8ba4\u7684\u201c\u6587\u7ae0\u201d\u7c7b\u578b\u3002\u5f53\u4f60\u628a\u6807\u7b7e\u6302\u8f7d\u5230\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u540e\uff0c\u4e24\u8005\u5728\u540e\u53f0\u5efa\u7acb\u4e86\u5173\u8054\uff0c\u4f46\u6807\u7b7e\u5b58\u6863\u9875\u9762\u7684\u67e5\u8be2\u673a\u5236\u5e76\u672a\u81ea\u52a8\u66f4\u65b0\u4ee5\u5305\u542b\u8fd9\u4e9b\u65b0\u7684\u5185\u5bb9\u7c7b\u578b\u3002<\/p><h2 class=\"wp-block-heading\">\u89e3\u51b3\u601d\u8def<\/h2><p>\u6700\u76f4\u63a5\u6709\u6548\u7684\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528 <code>pre_get_posts<\/code> \u94a9\u5b50\u51fd\u6570\uff0c\u5728WordPress\u6267\u884c\u4e3b\u67e5\u8be2\u4e4b\u524d\uff0c\u4fee\u6539\u5176\u67e5\u8be2\u53c2\u6570\uff0c\u8ba9\u5b83\u540c\u65f6\u83b7\u53d6\u9ed8\u8ba4\u6587\u7ae0\u548c\u4f60\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u3002<\/p><h2 class=\"wp-block-heading\">\u65b9\u6cd5\u4e00\uff1a\u81ea\u52a8\u68c0\u6d4b\u6240\u6709\u652f\u6301\u6807\u7b7e\u7684\u6587\u7ae0\u7c7b\u578b<\/h2><pre class=\"wp-block-code\"><code>\/**\n * \u81ea\u52a8\u83b7\u53d6\u6240\u6709\u652f\u6301\u6807\u7b7e\u5206\u7c7b\u6cd5\u7684\u6587\u7ae0\u7c7b\u578b\uff0c\u5e76\u5728\u6807\u7b7e\u5b58\u6863\u9875\u663e\u793a\u5b83\u4eec\n *\/\nfunction auto_add_all_tagged_post_types_to_archive($query) {\n    \/\/ \u786e\u4fdd\u5728\u524d\u7aef\u7684\u4e3b\u6807\u7b7e\u5b58\u6863\u9875\u9762\uff0c\u4e14\u4e0d\u662f\u7ba1\u7406\u540e\u53f0\n    if (is_tag() &amp;&amp; $query-&gt;is_main_query() &amp;&amp; !is_admin()) {\n\n        \/\/ \u83b7\u53d6\u6240\u6709\u516c\u5171\u7684\u6587\u7ae0\u7c7b\u578b\n        $all_post_types = get_post_types(array('public' =&gt; true));\n\n        \/\/ \u8fc7\u6ee4\u51fa\u652f\u6301\u6807\u7b7e\u5206\u7c7b\u6cd5\u7684\u6587\u7ae0\u7c7b\u578b\n        $tagged_post_types = array();\n        foreach ($all_post_types as $post_type) {\n            if (is_object_in_taxonomy($post_type, 'post_tag')) {\n                $tagged_post_types[] = $post_type;\n            }\n        }\n\n        \/\/ \u5982\u679c\u627e\u5230\u4e86\u652f\u6301\u6807\u7b7e\u7684\u6587\u7ae0\u7c7b\u578b\uff0c\u5c31\u8bbe\u7f6e\u67e5\u8be2\u53c2\u6570\n        if (!empty($tagged_post_types)) {\n            $query-&gt;set('post_type', $tagged_post_types);\n        }\n    }\n}\nadd_action('pre_get_posts', 'auto_add_all_tagged_post_types_to_archive');<\/code><\/pre><h2 class=\"wp-block-heading\">\u65b9\u6cd5\u4e8c\uff1a\u66f4\u7075\u6d3b\u7684\u89e3\u51b3\u65b9\u6848\uff08\u63a8\u8350\uff09<\/h2><pre class=\"wp-block-code\"><code>\/**\n * \u66f4\u7075\u6d3b\u7684\u89e3\u51b3\u65b9\u6848\uff1a\u81ea\u52a8\u5305\u542b\u6240\u6709\u652f\u6301\u6807\u7b7e\u7684\u6587\u7ae0\u7c7b\u578b\n * \u5e76\u63d0\u4f9b\u8fc7\u6ee4\u5668\u4f9b\u8fdb\u4e00\u6b65\u5b9a\u5236\n *\/\nfunction smart_tag_archive_query($query) {\n    \/\/ \u53ea\u5728\u4e3b\u67e5\u8be2\u7684\u6807\u7b7e\u5b58\u6863\u9875\u9762\u4f7f\u7528\n    if (is_tag() &amp;&amp; $query-&gt;is_main_query() &amp;&amp; !is_admin()) {\n\n        \/\/ \u4f7f\u7528\u7f13\u5b58\u63d0\u9ad8\u6027\u80fd\n        $tagged_post_types = get_transient('tagged_post_types');\n\n        if (false === $tagged_post_types) {\n            \/\/ \u83b7\u53d6\u6240\u6709\u516c\u5171\u6587\u7ae0\u7c7b\u578b\n            $all_post_types = get_post_types(array('public' =&gt; true));\n            $tagged_post_types = array();\n\n            foreach ($all_post_types as $post_type) {\n                \/\/ \u68c0\u67e5\u8be5\u6587\u7ae0\u7c7b\u578b\u662f\u5426\u652f\u6301\u6807\u7b7e\u5206\u7c7b\u6cd5\n                if (is_object_in_taxonomy($post_type, 'post_tag')) {\n                    $tagged_post_types[] = $post_type;\n                }\n            }\n\n            \/\/ \u7f13\u5b58\u7ed3\u679c12\u5c0f\u65f6\n            set_transient('tagged_post_types', $tagged_post_types, 12 * HOUR_IN_SECONDS);\n        }\n\n        \/\/ \u5141\u8bb8\u5f00\u53d1\u8005\u901a\u8fc7\u8fc7\u6ee4\u5668\u4fee\u6539\u8981\u5305\u542b\u7684\u6587\u7ae0\u7c7b\u578b\n        $final_post_types = apply_filters('tag_archive_post_types', $tagged_post_types);\n\n        if (!empty($final_post_types)) {\n            $query-&gt;set('post_type', $final_post_types);\n        }\n    }\n}\nadd_action('pre_get_posts', 'smart_tag_archive_query');\n\n\/**\n * \u5f53\u65b0\u7684\u6587\u7ae0\u7c7b\u578b\u6ce8\u518c\u65f6\u6e05\u9664\u7f13\u5b58\n *\/\nfunction clear_tagged_post_types_cache() {\n    delete_transient('tagged_post_types');\n}\nadd_action('registered_post_type', 'clear_tagged_post_types_cache');<\/code><\/pre><p>\u4e0a\u8ff0\u4ee3\u7801\u7f13\u5b58\u7ed3\u679c12\u5c0f\u65f6\u540e\uff0c\u8be5\u5b9e\u73b0\u529f\u80fd\u8fd8\u4f1a\u6709\u6548\u5417\uff1f<\/p><h3 class=\"wp-block-heading\">\u7f13\u5b58\u673a\u5236\u7684\u5de5\u4f5c\u6d41\u7a0b<\/h3><p>\u5728\u65b9\u6cd5\u4e8c\u4e2d\uff0c\u7f13\u5b58\u673a\u5236\u662f\u8fd9\u6837\u5de5\u4f5c\u7684\uff1a<\/p><pre class=\"wp-block-code\"><code>\/\/ \u4f7f\u7528\u7f13\u5b58\u63d0\u9ad8\u6027\u80fd\n$tagged_post_types = get_transient('tagged_post_types');\n\nif (false === $tagged_post_types) {\n    \/\/ \u7f13\u5b58\u4e0d\u5b58\u5728\u6216\u5df2\u8fc7\u671f\uff0c\u91cd\u65b0\u8ba1\u7b97\n    $all_post_types = get_post_types(array('public' =&gt; true));\n    $tagged_post_types = array();\n\n    foreach ($all_post_types as $post_type) {\n        if (is_object_in_taxonomy($post_type, 'post_tag')) {\n            $tagged_post_types[] = $post_type;\n        }\n    }\n\n    \/\/ \u7f13\u5b58\u7ed3\u679c12\u5c0f\u65f6\n    set_transient('tagged_post_types', $tagged_post_types, 12 * HOUR_IN_SECONDS);\n}<\/code><\/pre><h3 class=\"wp-block-heading\">12\u5c0f\u65f6\u540e\u4f1a\u53d1\u751f\u4ec0\u4e48<\/h3><p><strong>\u662f\u7684\uff0c12\u5c0f\u65f6\u540e\u529f\u80fd\u4ecd\u7136\u6709\u6548\uff01<\/strong> \u539f\u56e0\u5982\u4e0b\uff1a<\/p><ol class=\"wp-block-list\">\n<li><strong>\u7f13\u5b58\u81ea\u52a8\u8fc7\u671f<\/strong>\uff1a12\u5c0f\u65f6\u540e\uff0cTransient \u7f13\u5b58\u4f1a\u81ea\u52a8\u8fc7\u671f<\/li>\n\n\n\n<li><strong>\u81ea\u52a8\u91cd\u65b0\u8ba1\u7b97<\/strong>\uff1a\u5f53\u7f13\u5b58\u8fc7\u671f\u540e\uff0c<code>get_transient()<\/code> \u4f1a\u8fd4\u56de <code>false<\/code>\uff0c\u89e6\u53d1\u91cd\u65b0\u8ba1\u7b97\u903b\u8f91<\/li>\n\n\n\n<li><strong>\u83b7\u53d6\u6700\u65b0\u6570\u636e<\/strong>\uff1a\u91cd\u65b0\u8ba1\u7b97\u65f6\u4f1a\u83b7\u53d6\u5f53\u524d\u6240\u6709\u652f\u6301\u6807\u7b7e\u7684\u6587\u7ae0\u7c7b\u578b\uff0c\u5305\u62ec\u65b0\u6ce8\u518c\u7684\u7c7b\u578b<\/li>\n<\/ol><h3 class=\"wp-block-heading\">\u4e3b\u52a8\u7f13\u5b58\u6e05\u7406\u673a\u5236<\/h3><p>\u66f4\u91cd\u8981\u7684\u662f\uff0c\u65b9\u6cd5\u4e8c\u5305\u542b\u4e86<strong>\u4e3b\u52a8\u7f13\u5b58\u6e05\u7406<\/strong>\uff1a<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u5f53\u65b0\u7684\u6587\u7ae0\u7c7b\u578b\u6ce8\u518c\u65f6\u6e05\u9664\u7f13\u5b58\n *\/\nfunction clear_tagged_post_types_cache() {\n    delete_transient('tagged_post_types');\n}\nadd_action('registered_post_type', 'clear_tagged_post_types_cache');<\/code><\/pre><p>\u8fd9\u610f\u5473\u7740\uff1a<\/p><ul class=\"wp-block-list\">\n<li><strong>\u65e0\u9700\u7b49\u5f8512\u5c0f\u65f6<\/strong>\uff1a\u5f53\u6709\u65b0\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u6ce8\u518c\u65f6\uff0c\u7f13\u5b58\u4f1a\u7acb\u5373\u88ab\u6e05\u9664<\/li>\n\n\n\n<li><strong>\u5373\u65f6\u66f4\u65b0<\/strong>\uff1a\u4e0b\u6b21\u8bbf\u95ee\u6807\u7b7e\u9875\u9762\u65f6\u5c31\u4f1a\u91cd\u65b0\u8ba1\u7b97\u5e76\u5305\u542b\u65b0\u7684\u6587\u7ae0\u7c7b\u578b<\/li>\n<\/ul><h3 class=\"wp-block-heading\">\u6539\u8fdb\u5efa\u8bae\uff1a\u53cc\u91cd\u4fdd\u969c<\/h3><p>\u5982\u679c\u4f60\u60f3\u8981\u66f4\u52a0\u4fdd\u9669\uff0c\u53ef\u4ee5\u6dfb\u52a0\u989d\u5916\u7684\u7f13\u5b58\u6e05\u7406\u94a9\u5b50\uff1a<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u589e\u5f3a\u7684\u7f13\u5b58\u6e05\u7406\u673a\u5236\n *\/\nfunction comprehensive_cache_clear() {\n    delete_transient('tagged_post_types');\n}\n\n\/\/ \u5728\u591a\u79cd\u60c5\u51b5\u4e0b\u6e05\u7406\u7f13\u5b58\nadd_action('registered_post_type', 'comprehensive_cache_clear'); \/\/ \u65b0\u6587\u7ae0\u7c7b\u578b\u6ce8\u518c\nadd_action('registered_taxonomy', 'comprehensive_cache_clear');  \/\/ \u65b0\u5206\u7c7b\u6cd5\u6ce8\u518c\nadd_action('after_switch_theme', 'comprehensive_cache_clear');   \/\/ \u5207\u6362\u4e3b\u9898\u65f6\nadd_action('activated_plugin', 'comprehensive_cache_clear');     \/\/ \u6fc0\u6d3b\u63d2\u4ef6\u65f6\nadd_action('deactivated_plugin', 'comprehensive_cache_clear');   \/\/ \u505c\u7528\u63d2\u4ef6\u65f6<\/code><\/pre><p><strong>\u65b9\u6cd5\u4e8c\u7684\u7f13\u5b58\u8bbe\u8ba1\u662f\u5b89\u5168\u6709\u6548\u7684<\/strong>\uff1a<\/p><ul class=\"wp-block-list\">\n<li>\u2705 <strong>12\u5c0f\u65f6\u540e<\/strong>\uff1a\u7f13\u5b58\u81ea\u52a8\u8fc7\u671f\uff0c\u529f\u80fd\u6b63\u5e38<\/li>\n\n\n\n<li>\u2705 <strong>\u65b0\u6587\u7ae0\u7c7b\u578b\u6ce8\u518c\u65f6<\/strong>\uff1a\u7f13\u5b58\u7acb\u5373\u6e05\u9664\uff0c\u5373\u65f6\u751f\u6548<\/li>\n\n\n\n<li>\u2705 <strong>\u6027\u80fd\u4f18\u5316<\/strong>\uff1a\u907f\u514d\u6bcf\u6b21\u9875\u9762\u52a0\u8f7d\u90fd\u91cd\u65b0\u8ba1\u7b97<\/li>\n\n\n\n<li>\u2705 <strong>\u672a\u6765\u517c\u5bb9<\/strong>\uff1a\u81ea\u52a8\u9002\u5e94\u7cfb\u7edf\u53d8\u5316<\/li>\n<\/ul><p>\u8fd9\u4e2a\u8bbe\u8ba1\u5728\u6027\u80fd\u548c\u5b9e\u65f6\u6027\u4e4b\u95f4\u53d6\u5f97\u4e86\u5f88\u597d\u7684\u5e73\u8861\uff0c\u65e2\u907f\u514d\u4e86\u9891\u7e41\u7684\u6570\u636e\u5e93\u67e5\u8be2\uff0c\u53c8\u80fd\u53ca\u65f6\u54cd\u5e94\u7cfb\u7edf\u53d8\u5316\u3002<\/p><h2 class=\"wp-block-heading\">\u65b9\u6cd5\u4e09\uff1a\u5e26\u6392\u9664\u529f\u80fd\u7684\u589e\u5f3a\u7248\u672c<\/h2><pre class=\"wp-block-code\"><code>\/**\n * \u589e\u5f3a\u7248\u672c\uff1a\u81ea\u52a8\u5305\u542b\u6240\u6709\u652f\u6301\u6807\u7b7e\u7684\u6587\u7ae0\u7c7b\u578b\uff0c\u5e76\u53ef\u6392\u9664\u7279\u5b9a\u7c7b\u578b\n *\/\nfunction enhanced_tag_archive_solution($query) {\n    if (is_tag() &amp;&amp; $query-&gt;is_main_query() &amp;&amp; !is_admin()) {\n\n        $tagged_post_types = get_transient('enhanced_tagged_post_types');\n\n        if (false === $tagged_post_types) {\n            $all_post_types = get_post_types(array('public' =&gt; true));\n            $tagged_post_types = array();\n\n            foreach ($all_post_types as $post_type) {\n                $taxonomies = get_object_taxonomies($post_type);\n                if (in_array('post_tag', $taxonomies)) {\n                    $tagged_post_types[] = $post_type;\n                }\n            }\n\n            set_transient('enhanced_tagged_post_types', $tagged_post_types, 12 * HOUR_IN_SECONDS);\n        }\n\n        \/\/ \u9ed8\u8ba4\u6392\u9664\u7684\u6587\u7ae0\u7c7b\u578b\uff08\u53ef\u6839\u636e\u9700\u8981\u4fee\u6539\uff09\n        $default_excluded = array();\n\n        \/\/ \u5141\u8bb8\u901a\u8fc7\u8fc7\u6ee4\u5668\u4fee\u6539\u6392\u9664\u5217\u8868\n        $excluded_types = apply_filters('tag_archive_excluded_post_types', $default_excluded);\n\n        \/\/ \u4ece\u6700\u7ec8\u5217\u8868\u4e2d\u79fb\u9664\u88ab\u6392\u9664\u7684\u7c7b\u578b\n        $final_types = array_diff($tagged_post_types, $excluded_types);\n\n        if (!empty($final_types)) {\n            $query-&gt;set('post_type', $final_types);\n\n            \/\/ \u53ef\u9009\uff1a\u8bbe\u7f6e\u6bcf\u9875\u663e\u793a\u6570\u91cf\n            $posts_per_page = apply_filters('tag_archive_posts_per_page', get_option('posts_per_page'));\n            $query-&gt;set('posts_per_page', $posts_per_page);\n        }\n    }\n}\nadd_action('pre_get_posts', 'enhanced_tag_archive_solution');\n\n\/**\n * \u6ce8\u518c\u65b0\u6587\u7ae0\u7c7b\u578b\u65f6\u6e05\u9664\u7f13\u5b58\n *\/\nfunction clear_enhanced_tag_cache() {\n    delete_transient('enhanced_tagged_post_types');\n}\nadd_action('registered_post_type', 'clear_enhanced_tag_cache');<\/code><\/pre><h3 class=\"wp-block-heading\">\u4f7f\u7528\u793a\u4f8b\u548c\u81ea\u5b9a\u4e49\u65b9\u6cd5<\/h3><h4 class=\"wp-block-heading\">\u6392\u9664\u7279\u5b9a\u6587\u7ae0\u7c7b\u578b<\/h4><pre class=\"wp-block-code\"><code>\/\/ \u5728\u4e3b\u9898\u7684functions.php\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u6765\u6392\u9664\u7279\u5b9a\u6587\u7ae0\u7c7b\u578b\nadd_filter('tag_archive_excluded_post_types', function($excluded) {\n    \/\/ \u6392\u9664'attachment'\u548c'page'\u7c7b\u578b\n    $excluded[] = 'attachment';\n    $excluded[] = 'page';\n    return $excluded;\n});<\/code><\/pre><h4 class=\"wp-block-heading\">\u624b\u52a8\u5f3a\u5236\u5305\u542b\u67d0\u4e9b\u6587\u7ae0\u7c7b\u578b<\/h4><pre class=\"wp-block-code\"><code>\/\/ \u5f3a\u5236\u5305\u542b\u67d0\u4e9b\u6587\u7ae0\u7c7b\u578b\uff0c\u5373\u4f7f\u5b83\u4eec\u4e0d\u652f\u6301\u6807\u7b7e\nadd_filter('tag_archive_post_types', function($post_types) {\n    if (!in_array('my_custom_type', $post_types)) {\n        $post_types[] = 'my_custom_type';\n    }\n    return $post_types;\n});<\/code><\/pre><h4 class=\"wp-block-heading\">\u65b9\u6848\u7279\u70b9<\/h4><ol class=\"wp-block-list\">\n<li><strong>\u5b8c\u5168\u81ea\u52a8\u5316<\/strong>\uff1a\u65e0\u9700\u624b\u52a8\u6307\u5b9a\u6587\u7ae0\u7c7b\u578b<\/li>\n\n\n\n<li><strong>\u672a\u6765\u517c\u5bb9<\/strong>\uff1a\u81ea\u52a8\u9002\u5e94\u65b0\u6ce8\u518c\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b<\/li>\n\n\n\n<li><strong>\u6027\u80fd\u4f18\u5316<\/strong>\uff1a\u4f7f\u7528\u7f13\u5b58\u51cf\u5c11\u6570\u636e\u5e93\u67e5\u8be2<\/li>\n\n\n\n<li><strong>\u9ad8\u5ea6\u53ef\u5b9a\u5236<\/strong>\uff1a\u63d0\u4f9b\u8fc7\u6ee4\u5668\u4f9b\u5f00\u53d1\u8005\u5b9a\u5236<\/li>\n\n\n\n<li><strong>\u667a\u80fd\u6e05\u7406<\/strong>\uff1a\u6ce8\u518c\u65b0\u6587\u7ae0\u7c7b\u578b\u65f6\u81ea\u52a8\u6e05\u7406\u7f13\u5b58<\/li>\n<\/ol><h2 class=\"wp-block-heading\">\u65b9\u6848\u56db\uff1a\u786c\u7f16\u7801\u65b9\u6848<\/h2><p>\u5c06\u4e0b\u9762\u7684\u4ee3\u7801\u6dfb\u52a0\u5230\u5f53\u524d\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\u4e2d\uff1a<\/p><pre class=\"wp-block-code\"><code>\/**\n * \u8ba9\u6807\u7b7e\u5b58\u6863\u9875\u9762\u663e\u793a\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\n *\/\nfunction add_custom_post_types_to_tag_archive( $query ) {\n    \/\/ \u786e\u4fdd\u5728\u524d\u7aef\u7684\u4e3b\u6807\u7b7e\u5b58\u6863\u9875\u9762\uff0c\u4e14\u4e0d\u662f\u7ba1\u7406\u540e\u53f0\n    if ( is_tag() &amp;&amp; $query-&gt;is_main_query() &amp;&amp; ! is_admin() ) {\n        \/\/ \u6307\u5b9a\u8981\u663e\u793a\u7684\u6587\u7ae0\u7c7b\u578b\n        $post_types = array( 'post', '\u4f60\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b' ); \n        $query-&gt;set( 'post_type', $post_types );\n    }\n}\nadd_action( 'pre_get_posts', 'add_custom_post_types_to_tag_archive' );<\/code><\/pre><p><strong>\u4f7f\u7528\u8bf4\u660e\uff1a<\/strong><\/p><ul class=\"wp-block-list\">\n<li>\u5c06\u4ee3\u7801\u4e2d\u7684 <code>'\u4f60\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b'<\/code> \u66ff\u6362\u4e3a\u4f60\u5b9e\u9645\u4f7f\u7528\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u4f60\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u6709\u591a\u4e2a\uff0c\u53ef\u4ee5\u7ee7\u7eed\u6dfb\u52a0\u5230 <code>$post_types<\/code> \u6570\u7ec4\u4e2d\uff0c\u4f8b\u5982\uff1a<code>array( 'post', 'product', 'portfolio' )<\/code>\u3002<\/li>\n<\/ul><h2 class=\"wp-block-heading\">\u63a8\u8350\u4f7f\u7528<strong>\u65b9\u6cd5\u4e8c<\/strong><\/h2><p><strong>\u63a8\u8350\u4f7f\u7528\u65b9\u6cd5\u4e8c<\/strong>\uff0c\u5b83\u5728\u529f\u80fd\u5b8c\u6574\u6027\u548c\u6027\u80fd\u4e4b\u95f4\u53d6\u5f97\u4e86\u5f88\u597d\u7684\u5e73\u8861\uff0c\u5e76\u4e14\u63d0\u4f9b\u4e86\u8db3\u591f\u7684\u7075\u6d3b\u6027\u4f9b\u672a\u6765\u6269\u5c55\u3002<\/p><p>\u8fd9\u4e2a\u89e3\u51b3\u65b9\u6848\u5c06\u786e\u4fdd\u4f60\u7684\u6807\u7b7e\u5b58\u6863\u9875\u9762\u59cb\u7ec8\u663e\u793a\u6240\u6709\u652f\u6301\u6807\u7b7e\u5206\u7c7b\u6cd5\u7684\u6587\u7ae0\u7c7b\u578b\uff0c\u65e0\u8bba\u662f\u73b0\u5728\u5df2\u6709\u7684\u8fd8\u662f\u5c06\u6765\u65b0\u6ce8\u518c\u7684\u3002<\/p><h4 class=\"wp-block-heading\">\u8865\u5145\u6392\u67e5\u6b65\u9aa4<\/h4><p>\u5982\u679c\u4e0a\u8ff0\u65b9\u6cd5\u4ecd\u4e0d\u751f\u6548\uff0c\u5efa\u8bae\u6309\u4ee5\u4e0b\u6b65\u9aa4\u6392\u67e5\uff1a<\/p><ol class=\"wp-block-list\">\n<li><strong>\u786e\u8ba4\u5206\u7c7b\u6cd5\u5173\u8054<\/strong>\uff1a\u68c0\u67e5\u6ce8\u518c\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u6216\u5206\u7c7b\u6cd5\u7684\u4ee3\u7801\uff0c\u786e\u4fdd\u6807\u7b7e\uff08<code>post_tag<\/code>\uff09\u5df2\u6b63\u786e\u5173\u8054\u5230\u4f60\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u3002\u6709\u65f6\u4f1a\u4f7f\u7528 <code>register_taxonomy_for_object_type()<\/code> \u51fd\u6570\u6765\u5efa\u7acb\u8fd9\u79cd\u5173\u8054\u3002<\/li>\n\n\n\n<li><strong>\u68c0\u67e5\u6587\u7ae0\u7c7b\u578b\u652f\u6301<\/strong>\uff1a\u786e\u8ba4\u4f60\u7684\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u5728\u6ce8\u518c\u65f6\uff0c\u5728 <code>taxonomies<\/code> \u53c2\u6570\u4e2d\u5305\u542b\u4e86 <code>'post_tag'<\/code>\uff08\u6587\u7ae0\u6807\u7b7e\uff09\u3002<\/li>\n\n\n\n<li><strong>\u6e05\u9664\u7f13\u5b58<\/strong>\uff1a\u786e\u4fdd\u4f60\u6e05\u9664\u4e86\u6240\u6709\u53ef\u80fd\u5b58\u5728\u7684WordPress\u7f13\u5b58\u3001\u6d4f\u89c8\u5668\u7f13\u5b58\u6216CDN\u7f13\u5b58\uff0c\u4ee5\u4fbf\u770b\u5230\u66f4\u6539\u540e\u7684\u6548\u679c\u3002<\/li>\n\n\n\n<li><strong>\u5237\u65b0\u91cd\u5199\u89c4\u5219<\/strong>\uff1a\u5728WordPress\u540e\u53f0\u7684 <strong>\u8bbe\u7f6e &gt; \u56fa\u5b9a\u94fe\u63a5<\/strong> \u9875\u9762\uff0c\u76f4\u63a5\u70b9\u51fb\u201c\u4fdd\u5b58\u66f4\u6539\u201d\u5373\u53ef\u3002\u8fd9\u4f1a\u5237\u65b0WordPress\u7684\u91cd\u5199\u89c4\u5219\uff0c\u6709\u65f6\u662f\u89e3\u51b3\u95ee\u9898\u7684\u5173\u952e\u4e00\u6b65\u3002<\/li>\n<\/ol><h2 class=\"wp-block-heading\">\u603b\u7ed3<\/h2><p>\u901a\u8fc7 <code>pre_get_posts<\/code> \u94a9\u5b50\u4fee\u6539\u4e3b\u67e5\u8be2\u662f\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u6838\u5fc3\u65b9\u6cd5\u3002\u5982\u679c\u95ee\u9898\u4f9d\u65e7\uff0c\u518d\u6309\u7167\u6392\u67e5\u6b65\u9aa4\u9010\u4e00\u68c0\u67e5\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e2a\u95ee\u9898\u786e\u5b9e\u5f88\u5e38\u89c1\uff0c\u4f60\u9047\u5230\u7684\u60c5\u51b5\u662f\uff1a\u867d\u7136\u4ece\u5185\u5bb9\u7ba1\u7406\u7684\u89d2\u5ea6\u770b\uff0c\u6807\u7b7e\u5df2\u7ecf\u5173\u8054\u4e86\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff0c\u4f46\u5728\u524d\u53f0\u663e\u793a\u65f6\uff0cWordPress\u7684\u9ed8\u8ba4\u67e5\u8be2\u903b\u8f91\u5e76\u6ca1\u6709\u81ea\u52a8\u5305\u542b\u5b83\u4eec\u3002 \u95ee\u9898\u6839\u6e90\uff1a\u9ed8\u8ba4\u67e5\u8be2\u7684\u9650\u5236 WordPress\u7684\u6807\u7b7e\u5b58\u6863\u9875\u9ed8\u8ba4\u53ea\u67e5\u8be2\u7cfb\u7edf\u9ed8\u8ba4\u7684\u201c\u6587\u7ae0\u201d\u7c7b\u578b\u3002\u5f53\u4f60\u628a\u6807\u7b7e\u6302\u8f7d\u5230\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u540e\uff0c\u4e24\u8005\u5728\u540e\u53f0\u5efa\u7acb\u4e86\u5173\u8054\uff0c\u4f46\u6807\u7b7e\u5b58\u6863\u9875\u9762..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[50,59],"bjjc2nav":[34],"tuisongtax":[],"class_list":["post-4713","bjjc","type-bjjc","status-publish","hentry","tag-xsbdtj","tag-pzjc","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":"\u6807\u7b7e\u5173\u8054\u6587\u7ae0\u7c7b\u578b\u53ca\u663e\u793a","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":"\u6807\u7b7e\u5173\u8054\u6587\u7ae0\u7c7b\u578b\u53ca\u663e\u793a"}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc\/4713","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=4713"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=4713"},{"taxonomy":"bjjc2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc2nav?post=4713"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=4713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}