Field mapping with repeating fields

Help Desk ›› How to ›› Field mapping with repeating fields
25 November, 2020 14:31:10
johnmac78
Topics: 1
Messages: 4

I'm using Toolset Types plugin to create my custom fields. For a particular post type, I created a field to add images, which uses a repeating field.

With this plugin, repeating image fields are stored as separate postmeta values using the same meta key. For example, if there are two images in a repeating image field, there are two entries in postmeta for the corresponding post ID using the same meta key "wpcf-listing-photo".

(In my screenshot attached, you can see two entries in postmeta for the field slug wpcf-book-rept-img-1, both belonging to the post with ID 722.)

My issue is that when I use the E2PDF mapping function, it grabs the field code correctly in the backend, but in the PDF that's produced on the front end, only the first instance from the repeating field is shown.

[e2pdf-wp key="wpcf-listing-photo" meta="true"]

Is there a way to adjust this shortcode to target a specific postmeta value for the particular meta key? That is, the 2nd item, the 7th, or whatever?

Note: Toolset allows for a specific item in a repeating field to be targeted and displayed. I don't know if this would work with E2PDF's shortcode in some way. I include it here just in case.

types_render_field( "house-photos", array( "size"=>"thumbnail", "index" => "0") );

The index value targets a specific instance in a repeating field. 0=first, 1=second, etc.
25 November, 2020 17:12:09
E2Pdf
Support
Topics: 7
Messages: 3331
Hi,

Can you please create "textarea" field and map it with [e2pdf-wp key="wpcf-listing-photo" meta="true"] shortcode and attach screenshot of this part of PDF where this value rendered?

As about "backend", do you mean that it's rendered correctly while you are using "E2Pdf" -> "Export"?

Usually repeater entries stored as array in meta value, for which you can use "path" attribute to navigate, however it can be different on Toolset Types.

We remain at your service.
We would really appreciate your feedback at WordPress.org!
25 November, 2020 17:46:04
johnmac78
Topics: 1
Messages: 4
Oleksandr, thanks for prompt reply.

By backend, I mean in the Wordpress admin dashboard, specifically the E2PDF template builder. I just mean that when I map the field, it grabs the correct field in the template. And the image is successfully displayed on the exported PDF (but only the first image).

I've attached a screenshot of a sample PDF. I created a new text field as instructed. The boxed section at the bottom with the hyperlink is the text field and is mapped to [e2pdf-wp key="wpcf-listing-photo" meta="true"]. So a text field only grabs the URL, not the image file.

The eight images on the right are created using an image field mapped in the same way. As you can see, each shows only the first image in the repeating field. I need the second to show the 2nd, the third the 3rd, etc.
25 November, 2020 18:58:31
E2Pdf
Support
Topics: 7
Messages: 3331
It seems that Toolset Types has different way of saving repeater values, however E2Pdf uses default wordpress functionality to get post meta. We will check if we can add full compatibility with it in future releases.

As for now you can try to hook default output with adding filter to your theme functions.php

https://codeshare.io/5P6pBd

After adding function you must be able to use shortcode as follows:

[e2pdf-wp key="wpcf-listing-photo" meta="true" index="0"]
[e2pdf-wp key="wpcf-listing-photo" meta="true" index="1"]

and so on...

For correct usage "types_render_field" function must return "empty" value in case index not exists or url for image if image found, so maybe it will be need to add some parameters to "types_render_field". Unfortunately we can't test it on our side as we do not have yet access to Toolset Types plugin.

P.S. If it will still not work, can you please attach plugin to next message so we can check how it process the "types_render_field" function? You can mark message "private" so only we can see the message.

We remain at your service.
We would really appreciate your feedback at WordPress.org!
26 November, 2020 14:38:18
E2Pdf
Support
Topics: 7
Messages: 3331
Hi, thank you.

It seems we could find an issue. Here is updated code:

https://codeshare.io/alPkRD

Can you please try to update the code and check if it will work on your side.

We remain at your service.
We would really appreciate your feedback at WordPress.org!
26 November, 2020 15:39:03
johnmac78
Topics: 1
Messages: 4
Amazing! Works perfectly, as per attached file.

Really appreciate the quality support. And your plugin is exactly what I needed. I tried out a bunch of other options and yours is by far the best. The only one that easily maps Toolset custom fields and allows full control over the layout of the final PDF. Will possibly need to upgrade to pro level soon.

Thanks again.