{"id":31084,"date":"2024-11-25T17:35:38","date_gmt":"2024-11-25T09:35:38","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31084\/"},"modified":"2024-11-25T17:35:38","modified_gmt":"2024-11-25T09:35:38","slug":"wordpress%e4%b8%ad%e5%87%bd%e6%95%b0get_term_link%e7%9a%84%e5%8f%82%e6%95%b0%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31084\/","title":{"rendered":"WordPress\u4e2d\u51fd\u6570get_term_link\u7684\u53c2\u6570\u600e\u4e48\u8bbe\u7f6e"},"content":{"rendered":"<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/020\/5e1928a0433e8248.jpg\" class=\"aligncenter\" title=\"WordPress\u4e2d\u51fd\u6570get_term_link\u7684\u53c2\u6570\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" alt=\"WordPress\u4e2d\u51fd\u6570get_term_link\u7684\u53c2\u6570\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4e2d\u51fd\u6570get_term_link\u7684\u53c2\u6570\u600e\u4e48\u8bbe\u7f6e\uff1f<\/strong><\/p>\n<p>WordPress\u4e2d\u51fd\u6570get_term_link\u7684\u53c2\u6570\u8bbe\u7f6e\u95ee\u9898<\/p>\n<p>\u63a8\u8350\uff1a\u300a\u300b<\/p>\n<p>\u6700\u8fd1\u5e2e\u4e00\u4e2a\u670b\u53cb\u5199\u4f01\u4e1a\u7c7b\u4e3b\u9898\uff0c\u9700\u8981\u5bf9\u4ea7\u54c1\u8bbe\u5b9a\u4e00\u4e2a\u4e13\u95e8\u7684 post type \u540d\u53eb product\uff0c\u4e3a\u4e86\u7ba1\u7406\u65b9\u4fbf\u6027\uff0c\u6211\u5bf9 product \u8bbe\u7f6e\u4e86\u4e13\u95e8\u7684\u5206\u7c7b\u7c7b\u578b\u548c\u6807\u7b7e\u7c7b\u578b\uff0c\u5206\u7c7b\u7c7b\u578b\u4e3a product_cat\uff08WordPress \u672c\u8eab\u7684\u5206\u7c7b\u7c7b\u578b\u4e3a category\uff09\u3002<\/p>\n<p>\u4e3a\u4f55\u8981\u7528 get_term_link?\uff1a&nbsp;<\/p>\n<p>\u65b0\u7c7b\u578b\u7684\u5206\u7c7b\u662f\u65e0\u6cd5\u7528 \u8f93\u51fa\u5206\u7c7b\u94fe\u63a5\u5730\u5740\u7684\uff0c\u9700\u8981\u7528 get_term_link() \u51fd\u6570\uff0c\u6b64\u51fd\u6570\u7528\u6cd5\u5982\u4e0b\uff1a&nbsp;<\/p>\n<pre>&lt;?php  get_term_link( $term, $taxonomy ); ?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5177\u4f53\u53c2\u8003 WordPress Codex\uff1ahttp:\/\/codex.wordpress.org\/Function_Reference\/get_term_link&nbsp;<\/p>\n<p>\u95ee\u9898\uff1a&nbsp;<\/p>\n<p>\u4e3e\u4e2a\u4f8b\uff1a&nbsp;<\/p>\n<p>&#8211; \u81ea\u5b9a\u4e49\u5206\u7c7bID\u7684\u53d8\u91cf\u4e3a $term\uff0c$term \u662f\u6839\u636e\u540e\u53f0\u8bbe\u7f6e\u800c\u6539\u53d8\u7684\uff0c\u4e3a\u4e86\u65b9\u4fbf\u8bf4\u660e\uff0c\u8fd9\u91cc\u5047\u5b9a\u540e\u53f0\u53c2\u6570\u4e3a $custom_term = 8&nbsp;<\/p>\n<p>&#8211; \u6211\u8981\u83b7\u53d6\u81ea\u5b9a\u4e49\u5206\u7c7bID\u4e3a $term \u7684\u5206\u7c7b\u94fe\u63a5\u5730\u5740\uff0c\u90a3\u4e48\u6309\u7167\u5b98\u65b9\u8bf4\u660e\u5e94\u8be5\u662f\uff1a&nbsp;<\/p>\n<pre>&lt;?php  \n$term = $custom_term; \necho get_term_link( $term, &#039;product_cat&#039;); \n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u770b\u4f3c\u6ca1\u9519\uff0c\u4f46\u95ee\u9898\u6765\u4e86\uff0c\u8fd9\u6837\u4f1a\u8fd4\u56de\u9519\u8bef\uff1a&nbsp;<\/p>\n<p>Catchable fatal error\uff1a Object of class WP_Error could not be converted to string in.\u3002\u6ca1\u9519\u554a\uff0c\u76f4\u63a5\u7528 echo $term; \u8f93\u51fa\u7ed3\u679c\u7684\u786e\u662f 8\uff0c\u8fd9\u5c31\u8ba9\u4eba\u90c1\u95f7\u4e86\u2026\u2026&nbsp;<\/p>\n<p>\u4e0d\u8fc7\u5982\u679c\u4f60\u76f4\u63a5\u8fd9\u6837\uff1a&nbsp;<\/p>\n<pre>&lt;?php  echo get_term_link( 8, &#039;product_cat&#039;); ?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u53c8\u80fd\u6b63\u5e38\u5de5\u4f5c\u3002&nbsp;<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a&nbsp;<\/strong><\/p>\n<p>\u5728 WordPress Codex \u6253\u8f6c\u65f6\uff0c\u65e0\u610f\u4e2d\u770b\u5230\u56fd\u5916\u670b\u53cb\u4e5f\u78b0\u5230\u8fd9\u4e2a\u95ee\u9898\uff0c\u7136\u540e\u4ed6\u81ea\u5df1\u89e3\u51b3\u4e86\uff0c\u987f\u609f\u2026\u2026\u4f20\u9001\u95e8 \u300b&nbsp;<\/p>\n<p>\u539f\u6765\u662f\u53d8\u91cf\u7c7b\u578b\u95ee\u9898\uff0c\u8fd9 get_term_link \u51fd\u6570\u548c\u5176\u5b83\u5e38\u7528\u7684 WordPress \u51fd\u6570\u4e0d\u540c\uff0c\u4e0d\u4f1a\u81ea\u5df1\u8f6c\u6362\u53d8\u91cf\u7c7b\u578b\uff0c\u4f60\u5f97\u5148\u628a\u5b57\u7b26\u7c7b\u8f6c\u6362\u4e3a\u6574\u6570\u624d\u80fd\u6b63\u5e38\u5de5\u4f5c\uff0c\u597dOrz\u7684\u51fd\u6570\uff01&nbsp;<\/p>\n<p>\u4e0b\u9762\u8fd9\u6837\u5c31\u80fd\u6b63\u5e38\u5de5\u4f5c\uff1a&nbsp;<\/p>\n<p>\uff08\u5750\u5728\u6c99\u53d1\u4e0a\u7684Bolo\u6ce8\uff1aintval($term, 10)\u4f1a\u66f4\u597d\uff0c\u4e0d\u7136$term\u503c\u592a\u5927\u7684\u65f6\u5019\u4f1a\u6709\u8fdb\u5236\u8f6c\u6362\u95ee\u9898\uff0c\u8981\u4e48\u5c31\u7528(int)$term\uff09&nbsp;<\/p>\n<pre>&lt;?php  \n$term = $custom_term; \necho get_term_link( intval($term), &#039;product_cat&#039;); \n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6240\u4ee5\uff0c\u4ee5\u540e\u9047\u5230\u7c7b\u4f3c\u8fd9\u90c1\u95f7\u7684\u51fd\u6570\uff0c\u5c31\u8981\u8003\u8651\u662f\u4e0d\u662f\u53d8\u91cf\u6570\u636e\u7c7b\u578b\u95ee\u9898\u4e86\u3002&nbsp;<\/p>\n<p>\u6298\u817e\u73a9\uff08\u5b8c\uff09\u3002&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fWordPress\u4e2d\u51fd\u6570get_term_link\u7684\u53c2\u6570\u600e\u4e48\u8bbe\u7f6e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e2d\u51fd\u6570get_term_link\u7684\u53c2\u6570\u600e\u4e48\u8bbe\u7f6e\uff1f WordPress\u4e2d\u51fd\u6570get_term_link\u7684\u53c2\u6570\u8bbe\u7f6e\u95ee\u9898 \u63a8\u8350\uff1a\u300a\u300b \u6700\u8fd1\u5e2e\u4e00\u4e2a\u670b\u53cb\u5199\u4f01\u4e1a\u7c7b\u4e3b\u9898\uff0c\u9700\u8981\u5bf9\u4ea7\u54c1\u8bbe\u5b9a\u4e00\u4e2a\u4e13\u95e8\u7684 post type \u540d\u53eb product\uff0c\u4e3a\u4e86\u7ba1\u7406\u65b9\u4fbf\u6027\uff0c\u6211\u5bf9 product \u8bbe\u7f6e\u4e86\u4e13\u95e8\u7684\u5206\u7c7b\u7c7b\u578b\u548c\u6807\u7b7e\u7c7b\u578b\uff0c\u5206\u7c7b\u7c7b\u578b\u4e3a product_cat\uff08WordPress \u672c\u8eab\u7684\u5206\u7c7b\u7c7b\u578b\u4e3a category\uff09\u3002 \u4e3a\u4f55\u8981\u7528 get_term_link?\uff1a&nbsp; \u65b0\u7c7b\u578b\u7684\u5206\u7c7b\u662f\u65e0\u6cd5\u7528 \u8f93\u51fa\u5206\u7c7b\u94fe\u63a5\u5730\u5740\u7684\uff0c\u9700\u8981\u7528 get_term_link() \u51fd\u6570\uff0c\u6b64\u51fd\u6570\u7528\u6cd5\u5982\u4e0b\uff1a&nbsp; &lt;?php get_term_link( $term, $taxonomy ); ?&gt; \u767b\u5f55\u540e\u590d\u5236 \u5177\u4f53\u53c2\u8003 WordPress Codex\uff1ahttp:\/\/codex.wordpress.org\/Function_Reference\/get_term_link&nbsp; \u95ee\u9898\uff1a&nbsp; \u4e3e\u4e2a\u4f8b\uff1a&nbsp; &#8211; \u81ea\u5b9a\u4e49\u5206\u7c7bID\u7684\u53d8\u91cf\u4e3a $term\uff0c$term \u662f\u6839\u636e\u540e\u53f0\u8bbe\u7f6e\u800c\u6539\u53d8\u7684\uff0c\u4e3a\u4e86\u65b9\u4fbf\u8bf4\u660e\uff0c\u8fd9\u91cc\u5047\u5b9a\u540e\u53f0\u53c2\u6570\u4e3a $custom_term = 8&nbsp; &#8211; \u6211\u8981\u83b7\u53d6\u81ea\u5b9a\u4e49\u5206\u7c7bID\u4e3a $term \u7684\u5206\u7c7b\u94fe\u63a5\u5730\u5740\uff0c\u90a3\u4e48\u6309\u7167\u5b98\u65b9\u8bf4\u660e\u5e94\u8be5\u662f\uff1a&nbsp; &lt;?php $term = $custom_term; echo get_term_link( $term, &#039;product_cat&#039;); ?&gt; \u767b\u5f55\u540e\u590d\u5236 \u770b\u4f3c\u6ca1\u9519\uff0c\u4f46\u95ee\u9898\u6765\u4e86\uff0c\u8fd9\u6837\u4f1a\u8fd4\u56de\u9519\u8bef\uff1a&nbsp; Catchable fatal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-31084","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=31084"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31084\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}