Loading wp-load.php using require_once causes error in pdf generation using DomPDF

I have an external php file that contains the code to generate pdf using DOMPDF. I needed to access WordPress built-in functions in that file.
So, by following this link here, I included the following line:

require_once(plugins_url().'/../../wp-load.php');

Now, I am able to call WP functions, but the generated pdf is broken i.e I get “error trying to open the pdf..”.

Read More

If I comment out the require_once line, the pdf comes out fine. Any ideas why this might happen?

Related posts

Leave a Reply

1 comment

  1. Figured out my problem. What I was doing was this: I was fetching contents from a POST variable, and appending its content into the dompdf html. The problem, was I was including the wp-load.php file before fetching the POST variables. Hence my post variables were getting garbled, I suppose. Now, I changed the order i.e I read all the POST variables, saved them into other variables and then did include wp-load.php. Everything worked smooth then. Not sure whether this is the correct way, but it worked for me. Thanks for everyones help. I am marking this thread as solved