Skip to content
Advertisement

How to generate a pdf on post saving or updating

I’m trying to create a PDF from post content, including some ACF fields. Currently I’ve got it working on a POST form and dynamically creating a PDF each time, but I’d like to make it generate the PDF on saving the post so I can then just have a download button which downloads the PDF generated from saving the post, but having difficulty doing so. Any help would be grand!

I’ve tried to create this as a function in functions.php hooking into the acf/save_post action at prioirty 15 so it’s after the initial save.

JavaScript

I expect the code to create a pdf file in the wp-content/uploads/vehicledetails directory

error messages:

[01-Sep-2019 10:49:10 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:10 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:15 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:15 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:17 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:17 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:17 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:18 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:19 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:19 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:20 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:20 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:49:21 UTC] PHP Warning: require(wp-content/themes/murrayscott-nelson/fpdf/fpdf.php): failed to open stream: No such file or directory in /app/public/wp-content/themes/murrayscott-nelson/functions.php on line 81 [01-Sep-2019 10:49:21 UTC] PHP Warning: require(wp-content/themes/murrayscott-nelson/fpdf/fpdf.php): failed to open stream: No such file or directory in /app/public/wp-content/themes/murrayscott-nelson/functions.php on line 81 [01-Sep-2019 10:49:21 UTC] PHP Fatal error: require(): Failed opening required ‘wp-content/themes/murrayscott-nelson/fpdf/fpdf.php’ (include_path=’.:/usr/share/php:/www/wp-content/pear’) in /app/public/wp-content/themes/murrayscott-nelson/functions.php on line 81 [01-Sep-2019 10:49:21 UTC] PHP Fatal error: require(): Failed opening required ‘wp-content/themes/murrayscott-nelson/fpdf/fpdf.php’ (include_path=’.:/usr/share/php:/www/wp-content/pear’) in /app/public/wp-content/themes/murrayscott-nelson/functions.php on line 81 [01-Sep-2019 10:50:16 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:52:17 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:54:18 UTC] PHP Warning: Invalid argument supplied for foreach() in /app/public/wp-includes/class-wp-post-type.php on line 597 [01-Sep-2019 10:56:18 UTC] PHP Parse error: syntax error, unexpected ‘$vehicleName’ (T_VARIABLE), expecting function (T_FUNCTION) or const (T_CONST) in /app/public/wp-content/themes/murrayscott-nelson/functions.php on line 114 [01-Sep-2019 10:58:19 UTC] PHP Parse error: syntax error, unexpected ‘$vehicleName’ (T_VARIABLE), expecting function (T_FUNCTION) or const (T_CONST) in /app/public/wp-content/themes/murrayscott-nelson/functions.php on line 114

Advertisement

Answer

Your upload directory is not set correctly.

Try this:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement