{"id":16834,"date":"2023-12-15T13:09:02","date_gmt":"2023-12-15T12:09:02","guid":{"rendered":"https:\/\/www.welaunch.io\/en\/?post_type=faq&#038;p=16834"},"modified":"2023-12-17T20:27:23","modified_gmt":"2023-12-17T19:27:23","slug":"custom-taxonomies-wordpress-post-pdf","status":"publish","type":"faq","link":"https:\/\/www.welaunch.io\/en\/knowledge-base\/faq\/custom-taxonomies-wordpress-post-pdf\/","title":{"rendered":"Show custom Taxonomies in WordPress Post PDF"},"content":{"rendered":"<p>Creating a seamless and informative experience for users on your WordPress site often involves presenting detailed information in an organized manner. One way to enhance this experience is by showing<strong> custom taxonomies in your WordPress posts<\/strong>, especially when these posts are <strong>exported as PDFs<\/strong>. Custom taxonomies in WordPress are a powerful tool for categorizing and tagging content in a way that&#8217;s specific to your site&#8217;s needs, be it for products, services, or any other type of content.<\/p>\n<p>In this guide, we will delve into the process of displaying <strong>custom taxonomies in exported WordPress posts PDF<\/strong>. This feature is particularly useful for site owners who need to provide downloadable content, like product catalogs, informative articles, or resource guides, in a PDF format that retains all the essential categorization and tagging data. We&#8217;ll cover the necessary steps, from defining your custom taxonomies to modifying your PDF output, ensuring a comprehensive and user-friendly approach. Whether you&#8217;re a WordPress beginner or an experienced developer, this guide will equip you with the knowledge to enhance your site&#8217;s content presentation and usability.<\/p>\n<p>Please note you need our <a href=\"https:\/\/www.welaunch.io\/en\/product\/wordpress-posts-pdf\/\">wp posts to pdf plugin<\/a>. Then go into your <strong>functions.php of your child theme<\/strong> and add the below code. To adapt the code change the taxonomy keys in the <strong>$taxonomies variable<\/strong>.<\/p>\n<pre>\/\/ Add a filter to modify the post metadata keys.\r\nadd_filter('wordpress_print_posts_meta_keys', function($tmp) {\r\n\r\n    global $post; \/\/ Access the global post object.\r\n\r\n    \/\/ Define an array of taxonomy slugs to process.\r\n    $taxonomies = array(\r\n        'vehica_6659'\r\n    );\r\n\r\n    \/\/ Iterate through each taxonomy.\r\n    foreach($taxonomies as $taxonomy) {\r\n\r\n        \/\/ Get terms associated with the current post and taxonomy.\r\n        $terms = wp_get_object_terms($post-&gt;ID, $taxonomy);\r\n\r\n        \/\/ Check if any terms are associated.\r\n        if(!empty($terms)){\r\n\r\n            \/\/ Retrieve the full taxonomy object.\r\n            $taxonomy = get_taxonomy($taxonomy);\r\n\r\n            \/\/ Initialize an array to store term names.\r\n            $termNames = array();\r\n            foreach($terms as $term){\r\n                \/\/ Skip if the term name is not set or is empty.\r\n                if(!isset($term-&gt;name) || empty($term-&gt;name)) {\r\n                    continue;\r\n                }\r\n                \/\/ Add the term name to the array.\r\n                $termNames[] = $term-&gt;name;\r\n            }\r\n\r\n            \/\/ Add a new array to $tmp with taxonomy label and term names.\r\n            $tmp[] = array(\r\n                'key' =&gt;  $taxonomy-&gt;label,\r\n                'before' =&gt; $taxonomy-&gt;label . ': ',\r\n                'value' =&gt; implode(',', $termNames), \/\/ Combine term names into a string.\r\n            );\r\n        }\r\n    }\r\n\r\n    \/\/ Return the modified array.\r\n    return $tmp;\r\n\r\n});\r\n<\/pre>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","product_cat":[],"class_list":["post-16834","faq","type-faq","status-publish","hentry","faq_topics-posts-pages-to-pdf","faq_topics-posts-to-pdf-faq"],"_links":{"self":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/faq\/16834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/faq"}],"about":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/types\/faq"}],"author":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/comments?post=16834"}],"version-history":[{"count":1,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/faq\/16834\/revisions"}],"predecessor-version":[{"id":16835,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/faq\/16834\/revisions\/16835"}],"wp:attachment":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/media?parent=16834"}],"wp:term":[{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/product_cat?post=16834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}