• Resolved pixeltokig

    (@pixeltokig)


    Hello!

    We have a website with a theme we built from scratch with Advanced Custom Fields Pro and we want to be able to create PDF files from custom post types. We add the button with shortcode in the template file for the single post for the custom post type but when we click the button it generates an empty PDF file.

    Is your plugin compatible with ACF Pro? I tried reading the documentation but cant find anywhere that we have to add code to the template file to make it work.

    The website is this https://caskmoestue-staging.pixeltokig.se/produkter/100-hills-riesling

    Thanks so much in advance!

    • This topic was modified 7 years, 11 months ago by pixeltokig.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author dinamiko

    (@dinamiko)

    Hi pixeltokig,

    I did a tutorial about how to add custom fields to PDF using ACF ??

    https://www.dinamiko.com/add-custom-fields-pdf-using-advanced-custom-fields/

    Thanks,
    Emili

    Thread Starter pixeltokig

    (@pixeltokig)

    Hello Emili!

    Thank you so much!! ?? Really appreciate it! I will try this tomorrow.

    Kind regards, Christoffer

    Thread Starter pixeltokig

    (@pixeltokig)

    It works! Thank you so much!

    Hi there. I have just tried doing this but still not getting any output. Even if I am using the_content or the_title, it’s only showing the title of the archive page, not the titles of the posts displayed in the archive (custom posts). There seems to be something wrong with the loop? I have added an echo and it doesn’t seem to be returning any of my posts. I have hardcoded the CPT here which is “credits”.

    This is what I have in the template dkpdf-index.php

    <html>
        <head>
          <link type="text/css" rel="stylesheet" href="<?php echo get_bloginfo( 'stylesheet_url' ); ?>" media="all" />
          <?php 
            $wp_head = get_option( 'dkpdf_print_wp_head', '' );
            if( $wp_head == 'on' ) {
              wp_head();
            } 
          ?>
            <style type="text/css">
              body {
                background:#FFF;
                font-size: 100%;
              }
          <?php 
            $css = get_option( 'dkpdf_pdf_custom_css', '' );
            echo $css; 
          ?>      
        </style>
        </head>
        <body>
          <?php
          echo "dkpdf-index.php";
          global $post;
          $pdf  = get_query_var( 'pdf' );
          //$post_type = get_post_type( $pdf );
          $post_type = 'credits';
          $args = array(
            'p' => $pdf,
            'post_type' => $post_type,
            'post_status' => 'publish'
          );               
          $the_query = new WP_Query( apply_filters( 'dkpdf_query_args', $args ) );              
            if ( $the_query->have_posts() ) {     
              echo "yes have posts";
              while ( $the_query->have_posts() ) {
                  $the_query->the_post();
                  global $post; ?>
                  <?php 
                    // add your stuff here
                    the_content(); 
                    the_title(); 
                    the_field("description"); 
                  ?>
              <?php }
            }
            else{
              echo "don't have posts";
            }    
            wp_reset_postdata();
          ?>
        </body>
    </html>

    My theme is based on the Timber starter theme. Not sure if that could be the root of my problem?

    • This reply was modified 7 years, 7 months ago by anna_marie.
    Plugin Author dinamiko

    (@dinamiko)

    Hi anna_marie,

    that code is for getting one single post, try removing:

    'p' => $pdf, in $args

    Thanks,
    Emili

    Thanks Emili, that worked out great!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Generates empty PDF files from CPT with ACF’ is closed to new replies.