Variables in arg

WordPress
21 October, 2021 13:05:30
jimp
Topics: 2
Messages: 5
I am trying to display a variable inside the PDF template ($PRODNUM). I have tried [e2pdf-view id="2" arg1="'.$PRODNUM.'"] with [e2pdf-arg key="arg1"] inside the template, but it only returns the string '.$PRODNUM.' . I have echoed the variable on the page outside the template, so I know there is data in the variable.
21 October, 2021 23:17:19
E2Pdf
Support
Topics: 7
Messages: 3335
Hi,

If you are trying to put this shortcode inside WordPress Page Content - unfortunately it will not work as PHP variables not available in this context.

You have 2 possible solutions:

1. Output the shortcode via PHP via custom hook / action / editing wordpress page template as:

echo do_shortcode('[e2pdf-view id="2" dataset="' . $dataset . '" arg1="' . $PRODNUM . '"]');

* where $dataset must be the Page ID

OR

2. If $PRODNUM can be retrieved by Page ID, you can use shortcode inside E2Pdf Template as:

[e2pdf-wp key="prodnum" meta="true"]

and PHP filter which must be added to your functions.php / PHP snippet, where you will add code which will get $PRODNUM by Page ID (if it's not $_POST / $_GET post data) :

https://codeshare.io/VZj0Q3

We remain at your service.
We would really appreciate your feedback at WordPress.org!
22 October, 2021 11:20:53
jimp
Topics: 2
Messages: 5
Thank you so much for your response. Yes, $PRODNUM is retrieved through $_GET. And I simply inserted

$dataset = get_queried_object_id();

in my page template above your

echo do_shortcode('[e2pdf-view id="2" dataset="' . $dataset . '" arg1="' . $PRODNUM . '"]');

to get the Page ID, and it worked perfectly.

Thank you again! I have another question (pre-sale), but will post it in that section.