0

I have add a button to a custom post type that's supposed to generate a PDF from the custom post type using the ACF-Plugin. For that, I have to create a new Class (pdf) that's extending TCPDF. I built that class in a plugin.

The class basically uses ACF's function 'get_field_objects' to retrieve the post's data, as all the subfields are saved in Meta-Fields. I can, without any problems, execute the classes' function "generatePDF()" in the save-hook, but that's not what I want to do.

Basically I added a button using a meta box and want to execute the generatePDF-function when that button is clicked.

My first idea was to add another parameter "&generatepdf=true" to the current url, so one would land on the same page. I then added a simple if-statement

if($_GET['generatepdf'] == true) {
    $this->pdf->generatePDF()
}

to the end of my __construct function of my Custom Post Type to listen to that parameter. But obviously that code is being executed before everything on that page is loaded, which means I cannot access the "get_field_objects" function, as WP seems to not be "in the loop" at that point, before the page has finished loading.

I would appreciate any hint or help pointing me into the right direction.

Thanks in advance and best regards

NM

  • have you looked at the available hooks? – inarilo Dec 12 '17 at 11:26
  • try the hook "wp", in this hook the current custom post is stored in the global variable $_GLOBALS["post"] – mmm Dec 12 '17 at 11:53
  • I guess you are right and one might have solved this hooking into "WP", but in the end I replaced the "needed" button with a checkbox. Apparently "must haves" can be varied all day long :P Thank you guys! – N. M. Dec 12 '17 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.