{"id":1459,"date":"2019-04-09T15:56:53","date_gmt":"2019-04-09T10:26:53","guid":{"rendered":"http:\/\/blog.openwebsolutions.in\/?p=1459"},"modified":"2019-04-09T15:57:42","modified_gmt":"2019-04-09T10:27:42","slug":"generate-pdf-documents-wordpress-using-cpt-acf","status":"publish","type":"post","link":"https:\/\/openwebsolutions.in\/blog\/generate-pdf-documents-wordpress-using-cpt-acf\/","title":{"rendered":"How to Generate PDF Documents in WordPress using CPT and ACF"},"content":{"rendered":"<p>WordPress allows us to easily generate PDF files and make them available for download. In this blog, I&#8217;ll explain how to simply create and open the PDF files with <strong>CPT<\/strong> and <strong>ACF<\/strong> in the WordPress site.<\/p>\n<h3><span style=\"text-decoration: underline; color: #3a579a;\">Create ACF Field<\/span><\/h3>\n<p>Advanced Custom Fields is a WordPress plugin which allows us to add\u00a0<strong>extra content fields<\/strong>\u00a0to our WordPress.\u00a0Please follow the steps below.<\/p>\n<p>\u2022 First download,\u00a0<strong>Advance Custom Fields<\/strong> plugins.<\/p>\n<p>\u2022 Next, go to the <strong>plugins<\/strong> option from the dashboard menu &gt; <em>Activate<\/em> the plugins.<\/p>\n<p>\u2022\u00a0From the\u00a0<strong>Custom Fields<\/strong>\u00a0admin screen, click the\u00a0<strong>Add New<\/strong>\u00a0button to create a new field group.<\/p>\n<p>\u2022 Enter the field name &gt; Click Add Field option.<\/p>\n<p>\u2022 Type the <strong>Field Label<\/strong> such as &#8216;<em>PDF&#8217;<\/em>.<\/p>\n<p>\u2022 Select <em><strong>File<\/strong><\/em> option from<strong> Field Type.<\/strong><\/p>\n<p>\u2022 Choose <strong>Location<\/strong>, where my field will be generated &gt; Now <em>Publish<\/em> the ACF.<\/p>\n<h3><span style=\"text-decoration: underline; color: #3a579a;\">Create CPT UI Field<\/span><\/h3>\n<p>We can create our own custom post types and call them whatever we want. An amazing thing about this post type is that it can have different custom fields. Also, its own custom category structure. Plugins use is one of the easiest ways of creating a custom post type. Please follow the steps below.<\/p>\n<p>\u2022 At first, we need to do install and activate the\u00a0<a title=\"Custom Post Type UI\" href=\"https:\/\/wordpress.org\/plugins\/custom-post-type-ui\/\" target=\"_blank\" rel=\"nofollow noopener\">Custom Post Type UI\u00a0<\/a>plugin.<\/p>\n<p>\u2022 After activation, the plugin will add a new menu item in our WordPress admin menu called\u00a0<strong><em>CPT UI<\/em><\/strong>.<\/p>\n<p>\u2022 Now go to\u00a0<strong>CPT UI &gt; Add New<\/strong>\u00a0to create a new custom post type, named \u2018<em>Download<\/em>\u2019 and <strong>Post Type Slag<\/strong> named, \u2018<em>download-pdf<\/em>\u2019.<\/p>\n<p>\u2022 Now add a suitable icon from <strong>Dashicons<\/strong> (\u00a0<a href=\"https:\/\/developer.wordpress.org\/resource\/dashicons\/#palmtree\">https:\/\/developer.wordpress.org\/resource\/dashicons\/\u00a0<\/a>) for \u2018<em>Download<\/em>\u2019 CPT.<\/p>\n<p>\u2022 Check only <em>Title<\/em> option from\u00a0<strong>Supports<\/strong> field.<\/p>\n<p>\u2022 After creating CPT, go to \u2018<em>Download<\/em>\u2019\u2019 page in dashboard &gt; Click \u2018<em>Add new<\/em>\u2019 option.<\/p>\n<p>\u2022 Enter title. Next, click the <strong>Add File<\/strong> option and choose the <em>pdf file<\/em>. &gt; Next <em>Publish<\/em>.<\/p>\n<p>&nbsp;<\/p>\n<p>Now, go to\u00a0<strong><em>function.php<\/em>.\u00a0<\/strong>In the file<strong><em><strong>functions.php<\/strong><\/em>, <\/strong>write the following code to create a <em><strong>custom post type &#8211;\u00a0<\/strong><\/em><\/p>\n<pre>function get_download_pdf() {\r\n$args = array(\r\n'post_type'=&gt; 'download_pdf',\r\n'post_per_page' =&gt; 20,\r\n'order' =&gt; 'ASC'\r\n);\r\n$the_query = new WP_Query( $args );\r\n\r\necho '&lt;div class=\"row\"&gt;';\r\nwhile ($the_query&gt;have_posts()) : $the_query-&gt;the_post();\r\n\r\necho '&lt;div class=\"col-lg-12 col-md-12 col-sm-12 col-12\"&gt;';\r\necho '&lt;div class=\"pdf-download-field\"&gt;';\r\necho '&lt;h6&gt;'.get_the_title().'&lt;\/h6&gt;';\r\n$pdf = get_field( \"pdf\" );\r\necho '&lt;a href=\"'.$pdf.'\" target=\"_blank\"&gt;\r\n&lt;img src=\"'.get_stylesheet_directory_uri().'img-location\" alt=\"pdf\"&gt;&lt;\/a&gt;';\r\necho '&lt;a href=\"'.$pdf.'\" target=\"_blank\"&gt;\r\n&lt;i class=\"fa fa-download\"&gt;&lt;\/i&gt; Download&lt;\/a&gt;';\r\necho '&lt;\/div&gt;';\r\necho '&lt;\/div&gt;';\r\n\r\nendwhile;\r\n\r\necho '&lt;\/div&gt;';\r\n\r\n}\r\nadd_shortcode( 'download-pdf', 'get_download_pdf' );<\/pre>\n<p>Now go to the page\u00a0in the dashboard where it will generate the pdf file and put the shortcode [download-pdf ] there.<\/p>\n<h4 style=\"color: #3a579a;\"><strong>\/* CSS *\/\u00a0<\/strong><\/h4>\n<p>Add some custom style here.<\/p>\n<p>This is the simplest way to create a PDF file in WordPress.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress allows us to easily generate PDF files and make them available for download. In this blog, I&#8217;ll explain how to simply create and open the PDF files with CPT and ACF in the WordPress site. Create ACF Field Advanced Custom Fields is a WordPress plugin which allows us to add\u00a0extra content fields\u00a0to our WordPress.\u00a0Please [&hellip;]<\/p>\n","protected":false},"author":31,"featured_media":1465,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,115],"tags":[107,116,75],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Generate PDF Documents in WordPress using CPT and ACF<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/openwebsolutions.in\/blog\/generate-pdf-documents-wordpress-using-cpt-acf\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Generate PDF Documents in WordPress using CPT and ACF\" \/>\n<meta property=\"og:description\" content=\"WordPress allows us to easily generate PDF files and make them available for download. In this blog, I&#8217;ll explain how to simply create and open the PDF files with CPT and ACF in the WordPress site. Create ACF Field Advanced Custom Fields is a WordPress plugin which allows us to add\u00a0extra content fields\u00a0to our WordPress.\u00a0Please [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/openwebsolutions.in\/blog\/generate-pdf-documents-wordpress-using-cpt-acf\/\" \/>\n<meta property=\"og:site_name\" content=\"Openweb Solutions Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-09T10:26:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-09T10:27:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/03\/pdf.png\" \/>\n\t<meta property=\"og:image:width\" content=\"491\" \/>\n\t<meta property=\"og:image:height\" content=\"219\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/\",\"name\":\"Openweb Solutions Blog\",\"description\":\"Transforming ideas into reality\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/openwebsolutions.in\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/generate-pdf-documents-wordpress-using-cpt-acf\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/03\/pdf.png\",\"width\":491,\"height\":219,\"caption\":\"pdf\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/generate-pdf-documents-wordpress-using-cpt-acf\/#webpage\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/generate-pdf-documents-wordpress-using-cpt-acf\/\",\"name\":\"How to Generate PDF Documents in WordPress using CPT and ACF\",\"isPartOf\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/generate-pdf-documents-wordpress-using-cpt-acf\/#primaryimage\"},\"datePublished\":\"2019-04-09T10:26:53+00:00\",\"dateModified\":\"2019-04-09T10:27:42+00:00\",\"author\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/78cc69c3015b9c840d74591261861e22\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/openwebsolutions.in\/blog\/generate-pdf-documents-wordpress-using-cpt-acf\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/78cc69c3015b9c840d74591261861e22\",\"name\":\"Munmun Das\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/033db0a0941d27e1e3e3bdc05f2e1189?s=96&r=g\",\"caption\":\"Munmun Das\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1459"}],"collection":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/comments?post=1459"}],"version-history":[{"count":10,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1459\/revisions"}],"predecessor-version":[{"id":1562,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1459\/revisions\/1562"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media\/1465"}],"wp:attachment":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media?parent=1459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/categories?post=1459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/tags?post=1459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}