{"id":114,"date":"2020-09-12T12:41:30","date_gmt":"2020-09-12T12:41:30","guid":{"rendered":"https:\/\/barahasoft.com.np\/blog\/?p=114"},"modified":"2020-09-24T11:29:19","modified_gmt":"2020-09-24T11:29:19","slug":"how-to-fetch-post-tags-in-wordpress-api","status":"publish","type":"post","link":"https:\/\/barahasoft.com.np\/blog\/how-to-fetch-post-tags-in-wordpress-api\/","title":{"rendered":"How to fetch post tags in wordpress api?"},"content":{"rendered":"\n<p>we know WordPress provides rest API in default.Sometime we need to customize (add\/remove ) fields in response. In this blog we see how post tags can be added in our response without any plugin.  An application programming interface(API) is a computing interface which defines interactions between multiple software intermediaries. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow, etc. Here we add following few lines of codes in functions.php inside theme.<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ add post tags in response\nadd_action('rest_api_init', 'bs_rest_api_hooks');\n\nfunction bs_rest_api_hooks() {\n\n\tregister_rest_field(\n\t\t'post',\n\t\t'tags',\n\t\tarray(\n\t\t\t'get_callback' =&gt; 'bs_get_tags',\n\t\t)\n\t);\n\n}\n\nfunction bs_get_tags($object, $field_name, $request) {\n\n\t$strTags = &quot;&quot;;\n\n\t$tags = get_the_tags($object[&quot;id&quot;]);\n\tif (!empty($tags)) {\n\t\tforeach ($tags as $key =&gt; $value) {\n\t\t\tif (!empty($strTags)) {\n\t\t\t\t$strTags .= &quot;,&quot;;\n\t\t\t}\n\n\t\t\t$strTags .= getObjectValue($value, &quot;name&quot;,&quot;&quot;);\n\t\t}\n\t}\n\treturn $strTags;\n}\n<\/pre>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>we know WordPress provides rest API in default.Sometime we need to customize (add\/remove ) fields in response. In this blog we see how post tags can be added in our response without any plugin. An application programming interface(API) is a computing interface which defines interactions between multiple software intermediaries. It defines the kinds of calls [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":115,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":"Wordpress Api,tags in wp rest api,wp rest api,customize wp rest api response","yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to fetch post tags in wordpress api? - BS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/barahasoft.com.np\/blog\/how-to-fetch-post-tags-in-wordpress-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to fetch post tags in wordpress api? - BS Blog\" \/>\n<meta property=\"og:description\" content=\"we know WordPress provides rest API in default.Sometime we need to customize (add\/remove ) fields in response. In this blog we see how post tags can be added in our response without any plugin. An application programming interface(API) is a computing interface which defines interactions between multiple software intermediaries. It defines the kinds of calls [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/barahasoft.com.np\/blog\/how-to-fetch-post-tags-in-wordpress-api\/\" \/>\n<meta property=\"og:site_name\" content=\"BS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-12T12:41:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-24T11:29:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/barahasoft.com.np\/blog\/wp-content\/uploads\/2020\/09\/barahasoft-blog.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#website\",\"url\":\"https:\/\/barahasoft.com.np\/blog\/\",\"name\":\"BS Blog\",\"description\":\"Baraha Soft Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/barahasoft.com.np\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/how-to-fetch-post-tags-in-wordpress-api\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/barahasoft.com.np\/blog\/wp-content\/uploads\/2020\/09\/barahasoft-blog.jpg\",\"width\":1200,\"height\":500,\"caption\":\"BarahaSoft\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/how-to-fetch-post-tags-in-wordpress-api\/#webpage\",\"url\":\"https:\/\/barahasoft.com.np\/blog\/how-to-fetch-post-tags-in-wordpress-api\/\",\"name\":\"How to fetch post tags in wordpress api? - BS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/barahasoft.com.np\/blog\/how-to-fetch-post-tags-in-wordpress-api\/#primaryimage\"},\"datePublished\":\"2020-09-12T12:41:30+00:00\",\"dateModified\":\"2020-09-24T11:29:19+00:00\",\"author\":{\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#\/schema\/person\/4f97ce15b5eda1cd9fc64e3362dca065\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/barahasoft.com.np\/blog\/how-to-fetch-post-tags-in-wordpress-api\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#\/schema\/person\/4f97ce15b5eda1cd9fc64e3362dca065\",\"name\":\"Mahen\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2d90f77c4da8e61f15085bfd7b473714?s=96&d=mm&r=g\",\"caption\":\"Mahen\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","ads":{"ads-top":"https:\/\/barahasoft.com.np\/blog\/wp-content\/uploads\/2020\/07\/bottom.gif","ads-top-link":"https:\/\/play.google.com\/store\/apps\/details?id=np.com.barahasoft.mexpense","ads-bottom":"","ads-bottom-link":"","ads-side-top":"","ads-side-top-link":"","ads-side-bottom":"","ads-side-bottom-link":""},"_links":{"self":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/posts\/114"}],"collection":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/comments?post=114"}],"version-history":[{"count":3,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":135,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/posts\/114\/revisions\/135"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/media\/115"}],"wp:attachment":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/media?parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/categories?post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/tags?post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}