{"id":4197,"date":"2025-06-27T12:30:07","date_gmt":"2025-06-27T04:30:07","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4197.html"},"modified":"2025-12-11T10:14:38","modified_gmt":"2025-12-11T02:14:38","slug":"wordpress%e9%80%9a%e8%bf%87%e6%96%87%e7%ab%a0id%e6%89%beposttype%e5%90%8d","status":"publish","type":"bjjc","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4197.html","title":{"rendered":"WordPress\u901a\u8fc7\u6587\u7ae0ID\u67e5\u627e\u5bf9\u5e94\u7684post type\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u7684\u4e24\u79cd\u5b9e\u7528\u65b9\u6cd5"},"content":{"rendered":"<p>\u65b9\u6cd5\u5206\u4e24\u7c7b\uff1a\u6570\u636e\u5e93\u67e5\u8be2\u3001\u5185\u7f6e\u51fd\u6570\u3002<\/p><h2 class=\"wp-block-heading\">\u6570\u636e\u5e93\u67e5\u8be2\u65b9\u6cd5<\/h2><p>\u8981\u5728WordPress\u4e2d\u901a\u8fc7\u6587\u7ae0ID\u67e5\u627e\u5bf9\u5e94\u7684post type\u540d\u79f0\uff0c\u53ef\u4ee5\u4f7f\u7528WordPress\u7684\u6570\u636e\u5e93\u67e5\u8be2\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b8c\u6574\u7684PHP\u4ee3\u7801\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\uff1a<\/p><pre class=\"wp-block-code\"><code>\/\/ \u5047\u8bbe\u4f60\u5df2\u7ecf\u5305\u542b\u4e86wp-load.php\u6765\u521d\u59cb\u5316WordPress\u73af\u5883\nrequire_once('path\/to\/wp-load.php');\n\nfunction zzw_get_post_type_by_id($post_id) {\n    global $wpdb;\n    \n    \/\/ \u67e5\u8be2\u6587\u7ae0\u8868\u4ee5\u83b7\u53d6post_type\u5b57\u6bb5\n    $query = $wpdb-&gt;prepare(\"SELECT post_type FROM $wpdb-&gt;posts WHERE ID = %d\", $post_id);\n    $post_type = $wpdb-&gt;get_var($query);\n\n    if ($post_type) {\n        return $post_type;\n    } else {\n        return 'No post found with the given ID.';\n    }\n}\n\n\/\/ \u793a\u4f8b\uff1a\u901a\u8fc7\u6587\u7ae0ID\u83b7\u53d6post type\u540d\u79f0\n$post_id = 456; \/\/ \u66ff\u6362\u4e3a\u4f60\u8981\u67e5\u8be2\u7684\u6587\u7ae0ID\n$post_type_name = zzw_get_post_type_by_id($post_id);\necho \"The post type of post ID {$post_id} is: {$post_type_name}\";<\/code><\/pre><h3 class=\"wp-block-heading\">\u4f7f\u7528\u8bf4\u660e\uff1a<\/h3><ol class=\"wp-block-list\">\n<li>\u5c06\u4e0a\u8ff0\u4ee3\u7801\u4fdd\u5b58\u5230\u4e00\u4e2aPHP\u6587\u4ef6\u4e2d\u3002<\/li>\n\n\n\n<li>\u786e\u4fdd<code>require_once('path\/to\/wp-load.php');<\/code>\u8fd9\u884c\u4ee3\u7801\u4e2d\u7684\u8def\u5f84\u6307\u5411\u4f60\u7684WordPress\u5b89\u88c5\u76ee\u5f55\u4e0b\u7684<code>wp-load.php<\/code>\u6587\u4ef6\u3002<\/li>\n\n\n\n<li>\u4fee\u6539<code>$post_id<\/code>\u53d8\u91cf\u4e3a\u4f60\u60f3\u8981\u67e5\u8be2\u7684\u5b9e\u9645\u6587\u7ae0ID\u3002<\/li>\n\n\n\n<li>\u8fd0\u884c\u8be5PHP\u811a\u672c\u3002<\/li>\n<\/ol><p>\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u8f93\u51fa\u6307\u5b9a\u6587\u7ae0ID\u5bf9\u5e94\u7684\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\uff08\u4f8b\u5982\uff0c<code>post<\/code>, <code>page<\/code>, <code>custom_post_type<\/code>\u7b49\uff09\u3002\u5982\u679c\u627e\u4e0d\u5230\u5bf9\u5e94\u7684\u6587\u7ae0\uff0c\u5219\u4f1a\u8fd4\u56de&#8221;No post found with the given ID.&#8221;\u7684\u4fe1\u606f\u3002<\/p><h2 class=\"wp-block-heading\">\u5185\u7f6e\u51fd\u6570\u65b9\u6cd5<\/h2><p>\u5728WordPress\u4e2d\uff0c\u9664\u4e86\u901a\u8fc7\u6570\u636e\u5e93\u67e5\u8be2\u6765\u83b7\u53d6\u6587\u7ae0ID\u5bf9\u5e94\u7684post type\u540d\u79f0\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528WordPress\u63d0\u4f9b\u7684\u5185\u7f6e\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff1a<\/p><ol class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528 <code>get_post_type()<\/code> \u51fd\u6570<\/strong>: WordPress\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5185\u7f6e\u51fd\u6570<code>get_post_type()<\/code>\uff0c\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u6587\u7ae0ID\u83b7\u53d6\u5176post type\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528 <code>get_post()<\/code> \u51fd\u6570<\/strong>: \u4f60\u53ef\u4ee5\u5148\u83b7\u53d6\u6587\u7ae0\u5bf9\u8c61\uff0c\u7136\u540e\u4ece\u5bf9\u8c61\u4e2d\u63d0\u53d6post type\u4fe1\u606f\u3002<\/li>\n<\/ol><p>\u4e0b\u9762\u662f\u6bcf\u79cd\u65b9\u6cd5\u7684\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b\uff1a<\/p><h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528\u00a0<code>get_post_type()<\/code>\u00a0\u51fd\u6570<\/h3><pre class=\"wp-block-code\"><code>\/\/ \u5047\u8bbe\u4f60\u5df2\u7ecf\u5305\u542b\u4e86wp-load.php\u6765\u521d\u59cb\u5316WordPress\u73af\u5883\nrequire_once('path\/to\/wp-load.php');\n\nfunction zzw_get_post_type_by_id($post_id) {\n    $post_type = get_post_type($post_id);\n    \n    if ($post_type) {\n        return $post_type;\n    } else {\n        return 'No post found with the given ID.';\n    }\n}\n\n\/\/ \u793a\u4f8b\uff1a\u901a\u8fc7\u6587\u7ae0ID\u83b7\u53d6post type\u540d\u79f0\n$post_id = 456; \/\/ \u66ff\u6362\u4e3a\u4f60\u8981\u67e5\u8be2\u7684\u6587\u7ae0ID\n$post_type_name = zzw_get_post_type_by_id($post_id);\necho \"The post type of post ID {$post_id} is: {$post_type_name}\";<\/code><\/pre><h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e8c\uff1a\u4f7f\u7528\u00a0<code>get_post()<\/code>\u00a0\u51fd\u6570<\/h3><pre class=\"wp-block-code\"><code>\/\/ \u5047\u8bbe\u4f60\u5df2\u7ecf\u5305\u542b\u4e86wp-load.php\u6765\u521d\u59cb\u5316WordPress\u73af\u5883\nrequire_once('path\/to\/wp-load.php');\n\nfunction zzw_get_post_type_by_id($post_id) {\n    $post = get_post($post_id);\n    \n    if ($post) {\n        return $post-&gt;post_type;\n    } else {\n        return 'No post found with the given ID.';\n    }\n}\n\n\/\/ \u793a\u4f8b\uff1a\u901a\u8fc7\u6587\u7ae0ID\u83b7\u53d6post type\u540d\u79f0\n$post_id = 456; \/\/ \u66ff\u6362\u4e3a\u4f60\u8981\u67e5\u8be2\u7684\u6587\u7ae0ID\n$post_type_name = zzw_get_post_type_by_id($post_id);\necho \"The post type of post ID {$post_id} is: {$post_type_name}\";<\/code><\/pre><h3 class=\"wp-block-heading\">\u4f7f\u7528\u8bf4\u660e\uff1a<\/h3><ol class=\"wp-block-list\">\n<li>\u5c06\u4e0a\u8ff0\u4ee3\u7801\u4fdd\u5b58\u5230\u4e00\u4e2aPHP\u6587\u4ef6\u4e2d\u3002<\/li>\n\n\n\n<li>\u786e\u4fdd<code>require_once('path\/to\/wp-load.php');<\/code>\u8fd9\u884c\u4ee3\u7801\u4e2d\u7684\u8def\u5f84\u6307\u5411\u4f60\u7684WordPress\u5b89\u88c5\u76ee\u5f55\u4e0b\u7684<code>wp-load.php<\/code>\u6587\u4ef6\u3002<\/li>\n\n\n\n<li>\u4fee\u6539<code>$post_id<\/code>\u53d8\u91cf\u4e3a\u4f60\u60f3\u8981\u67e5\u8be2\u7684\u5b9e\u9645\u6587\u7ae0ID\u3002<\/li>\n\n\n\n<li>\u8fd0\u884c\u8be5PHP\u811a\u672c\u3002<\/li>\n<\/ol><p>\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u975e\u5e38\u7b80\u5355\u4e14\u9ad8\u6548\uff0c\u63a8\u8350\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u4f7f\u7528\u3002<code>get_post_type()<\/code>\u51fd\u6570\u66f4\u4e3a\u76f4\u63a5\uff0c\u800c<code>get_post()<\/code>\u51fd\u6570\u5219\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7075\u6d3b\u6027\uff0c\u56e0\u4e3a\u4f60\u53ef\u4ee5\u5728\u83b7\u53d6\u5230\u6587\u7ae0\u5bf9\u8c61\u540e\u8fdb\u4e00\u6b65\u5904\u7406\u5176\u4ed6\u5c5e\u6027\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u65b9\u6cd5\u5206\u4e24\u7c7b\uff1a\u6570\u636e\u5e93\u67e5\u8be2\u3001\u5185\u7f6e\u51fd\u6570\u3002 \u6570\u636e\u5e93\u67e5\u8be2\u65b9\u6cd5 \u8981\u5728WordPress\u4e2d\u901a\u8fc7\u6587\u7ae0ID\u67e5\u627e\u5bf9\u5e94\u7684post type\u540d\u79f0\uff0c\u53ef\u4ee5\u4f7f\u7528WordPress\u7684\u6570\u636e\u5e93\u67e5\u8be2\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b8c\u6574\u7684PHP\u4ee3\u7801\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\uff1a \u4f7f\u7528\u8bf4\u660e\uff1a \u8fd9\u6bb5\u4ee3\u7801\u4f1a\u8f93\u51fa\u6307\u5b9a\u6587\u7ae0ID\u5bf9\u5e94\u7684\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\uff08\u4f8b\u5982\uff0cpost, page, cust..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":true},"tags":[3195],"bjjc2nav":[14],"tuisongtax":[],"class_list":["post-4197","bjjc","type-bjjc","status-publish","hentry","tag-zmcff","bjjc2nav-jdztkf"],"acf":{"qian_art_seotitle":"WordPress\u901a\u8fc7\u6587\u7ae0ID\u67e5\u627e\u5bf9\u5e94\u7684post type\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u7684\u4e24\u79cd\u5b9e\u7528\u65b9\u6cd5","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":"WordPress\u901a\u8fc7\u6587\u7ae0ID\u67e5\u627e\u5bf9\u5e94\u7684post type\u6587\u7ae0\u7c7b\u578b\u540d\u79f0\u7684\u4e24\u79cd\u5b9e\u7528\u65b9\u6cd5"},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"\u6587\u7ae0\uff1a\u67e5\u627e\u5bf9\u5e94\u7684\u6587\u7ae0\u7c7b\u578b\u540d\u79f0","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":"\u6587\u7ae0\uff1a\u67e5\u627e\u5bf9\u5e94\u7684\u6587\u7ae0\u7c7b\u578b\u540d\u79f0"}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc\/4197","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=4197"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=4197"},{"taxonomy":"bjjc2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc2nav?post=4197"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=4197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}