in Template print field values from related post (different type)

May 05, 2024 03:58:25
lukashwm
Topics: 2
Messages: 10
Hello !

I have two post types lets say X and Y. Now I am going to create PDF files from Y which Parent is X and I want to use fields which are stored in X. The Posttypes have a (X) 1:n (Y) relationship.

I think I can create a function which takes the post ID as a parameter and returns the fields and than call this function via shortcode in the template builder? Is it possible and if how?

Thanks in advance, have a nice week !
May 05, 2024 04:06:28
E2Pdf
Topics: 7
Messages: 3617
Support
Hello,

Yes, it must be possible if you can get the Post ID of X: https://e2pdf.com/docs/extensions/wordpress#id. The construction should be as follows:

[e2pdf-wp id="dynamic" key="metakey" meta="true"][e2pdf-wp key="metakey2" meta="true"][/e2pdf-wp]

* where [e2pdf-wp key="metakey2" meta="true"] must output the Post ID from which you need to get the data, it can also be as: [e2pdf-wp key="post_parent"], or any other shortcode, etc.

P.S. Keep attention please that if the same element/object has another [e2pdf-wp] shortcodes in "Value", shortcodes must be closed, as: [e2pdf-wp key="ID"][/e2pdf-wp]


We would really appreciate your feedback at WordPress.org!
May 05, 2024 05:27:47
lukashwm
Topics: 2
Messages: 10
Hey, many thanks for the insane fast respond !

I've tried:

[e2pdf-wp id="dynamic" key="wpcf-custom-field-slug-from-X" meta="true"][e2pdf-wp key="post-id-of-X" meta="true"][/e2pdf-wp]

but nothing is outputted. Is there also a Debug option somehow?
May 05, 2024 06:09:59
E2Pdf
Topics: 7
Messages: 3617
Support
[e2pdf-wp key="post-id-of-X" meta="true"] - must output the Post ID, where post-id-of-X is a META KEY that stores the ID of the X post in the Y post. It must not be set to Post ID.

If you need to get data from the "static" post, just by the known ID, the shortcode will be just simple:

[e2pdf-wp id="123" key="wpcf-custom-field-slug-from-X" meta="true"]

* where "123" is your pre-defined Post ID.

======================================

If you still need to find out from the relation, you need to find which shortcode outputs the ID of the X post and put that code in the middle of the shortcode with the id="dynamic", for example if "X" is a parent post of "Y":

[e2pdf-wp id="dynamic" key="wpcf-custom-field-slug-from-X" meta="true"][e2pdf-wp key="post_parent"][/e2pdf-wp]



We would really appreciate your feedback at WordPress.org!
May 05, 2024 06:46:35
lukashwm
Topics: 2
Messages: 10
Well, that's exactly how I understood the codes.
But even [e2pdf-wp id="123" key="wpcf-custom-field-slug-from-X" meta="true"] does not output anything. The other field from actual posts are working fine.

In the end I need it dynamic but I can store the related post id of X in a Y field that's not a problem.

The Post types are different is that a problem? But they are both abstractions of typical Wordpress Posts which also support get_post_meta()

curious...
May 05, 2024 06:49:49
E2Pdf
Topics: 7
Messages: 3617
Support
No, it must not be a problem. It could be that you are using an incorrect meta key. Can you please create an E2Pdf template connected to the X post type and check via "Visual Mapper" which meta keys are available by part of the key that you are trying to use?

We would really appreciate your feedback at WordPress.org!
May 05, 2024 06:57:30
lukashwm
Topics: 2
Messages: 10
Did it, but nothing.

This is out Template for X provided by the plugin:
[e2pdf-wp key="wpcf-sl-kunde" meta="true"]

This is what I used in my original Template for Y:
[e2pdf-wp id="dynamic" key="wpcf-sl-kunde" meta="true"][e2pdf-wp key="10004" meta="true"][/e2pdf-wp]


Where 10004 is the id of a random post of type X with value in field: "wpcf-sl-kunde"
May 05, 2024 06:59:42
E2Pdf
Topics: 7
Messages: 3617
Support
[e2pdf-wp key="10004" meta="true"] - will output nothing, as 10004 is the Post ID and not the Meta Key. Incorrectly used shortcode.

[e2pdf-wp id="10004" key="wpcf-sl-kunde" meta="true"] - must output your value.

[e2pdf-wp id="dynamic" key="wpcf-sl-kunde" meta="true"]10004[/e2pdf-wp] - must output your value.

We would really appreciate your feedback at WordPress.org!
May 05, 2024 07:09:31
lukashwm
Topics: 2
Messages: 10
Sorry but [e2pdf-wp id="10004" key="wpcf-sl-kunde" meta="true"] and [e2pdf-wp id="dynamic" key="wpcf-sl-kunde" meta="true"]10004[/e2pdf-wp] are outputting nothing. See attached screenshots.
May 05, 2024 07:19:02
E2Pdf
Topics: 7
Messages: 3617
Support
Is that field created with ACF?

Can you please attach the screenshot with the field SL-Kunde setup? You can mark message private so only we can see the message.

P.S. We also recommend doing checks with the "textarea" object instead of the "HTML" object.


We would really appreciate your feedback at WordPress.org!
May 05, 2024 07:31:17
lukashwm
Topics: 2
Messages: 10
nah, it is created with Toolset (https://toolset.com/de/). And there is no critical information so it can stay public may be it helps others ;)
May 05, 2024 07:39:25
lukashwm
Topics: 2
Messages: 10
The system runs under PHP 8.3 FPM if thats may be important
May 05, 2024 07:44:25
E2Pdf
Topics: 7
Messages: 3617
Support
The setup looks correct and should work...

Can you please create a new "textarea" in the E2Pdf Template, with the same shortcode:

[e2pdf-wp id="10004" key="wpcf-sl-kunde" meta="true"] as value.

If it still won't work, unfortunately, we would need to take a look on your side directly. If it's acceptable for you, you can submit a support ticket with access details to the WP Admin Dashboard here: [private]

We would really appreciate your feedback at WordPress.org!
May 05, 2024 08:05:18
lukashwm
Topics: 2
Messages: 10
Well, new Text Area Field solved the problem. Jeeesus :D damn technology...

Also the dynamic option does work !

Awesome guys ! Really appreciate your response time thats absolutely incredible as also the plugin is !!!!!!!!!!!

Well played !
May 05, 2024 08:08:02
E2Pdf
Topics: 7
Messages: 3617
Support
It must also work with the HTML/Input object that you used. It seems you set some actions that were removing or hiding your "HTML" object with which you did tests, that's why it could not display anything, or the "value" was inserted malformed (Best way to set it is via "Right Mouse Click" -> "Properties" -> "Value")

We would really appreciate your feedback at WordPress.org!
Get News and Updates
Our monthly newsletter keeps you in the loop, so you'll always be up to date with the latest news and updates about E2Pdf.
* You can update your email subscription preferences here.
All trademarks, service marks, trade names, product names, and logos appearing on this website are the property of their respective owners. The use of trademarks such as Formidable Forms®, Forminator Forms®, Gravity Forms®, JetFormBuilder®, WordPress®, WooCommerce®, WPForms® and others is solely for identification purposes (nominative use) and does not imply any affiliation, sponsorship, or endorsement by the respective trademark holders.
© 2017 - 2026, https://e2pdf.com

We use cookies to collect and analyse information on site performance and usage, to provide social media features and to enhance and customise content and advertisements. By clicking "Accept Selected", you consent to use of selected cookies according to our Cookie Policy.