Skip Navigation

[Resolved] incrementor, register shortcode, repeating field, repeating image, multi instance image, custom shortcode

This thread is resolved. Here is a description of the problem and solution.

Problem:
I am trying to pass a variable to the index='n' field when displaying an repeater image from a custom post type. I am using [incrementor] shortcode that returns the number in the view loop.

Solution:
I have registered [incrementor] shortcode in website and now it is working as expected.

Basically to use custom shortcode, you need to register the shortcode first in Toolset >> Settings >> Front-end Content >> Third-party shortcode arguments. Screenshot here:
https://d7j863fr5jhrr.cloudfront.net/wp-content/uploads/2017/05/527111-register_shortcode.png?x50174

Relevant Documentation:
https://toolset.com/documentation/user-guides/shortcodes-within-shortcodes/

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 8 replies, has 2 voices.

Last updated by jonS-2 6 years, 10 months ago.

Assisted by: Noman.

Author
Posts
#526072

I am trying to pass a variable to the index='n' field when displaying an repeater image from a custom post type:

My example:
[types field='poster-artwork' size='shop_catalog' align='none' resize='proportional' id='$current_page' index='2'][/types]

It is clear the id="n" accepts a global variable (specifically $current_page) but it seems the only variable that the index accepts in a number.

Ive tried:
[types field='poster-artwork' size='shop_catalog' align='none' resize='proportional' id='$current_page' index='[incrementor]'][/types]

Where [incrementor] is a shortcode that returns the number in the view loop. Using the shortcode doesn't work. I am either calling the shortcode function incorrectly, or this isn't possible this way.

Can you assist with a way to pass this view an index number.

#526187

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

multiple images.png

Hi Jon,

Thank you for contacting Toolset Support. You can use repeating fields to display multiple images using the interface options of Toolset Types & Views, please see attached screenshot.

1. Can you please more clarify that why you want to achieve this using code? Or if I am not getting you right can you please provide step by step details that what you want to achieve? (preferably with back-end screenshots).

2. What you expected to see on the front page?
3. What you actually see right now (preferably with front-end screenshot or Link to page)?

Thank you

#526407
Back end.jpg
Front end.jpg

Yes,
I have a CPT called 'posters' and one of the fields is a multi instance image field called 'poster artwork'.

I am trying to display all the products that the customer can purchase for this poster.

Each instance of this 'poster artwork' field contains an image of a mockup of what the poster will look like if purchased. (In order - main, poster medium, mug, poster small.)

The content template of the CPT 'posters' includes a view that shows all the woocommerce products associated to this type of poster.

I wish to display the 'poster artwork' in each instance of these products. Refer "Front end.jpg". As you can see, this is displaying the products perfectly, however, the index of the 'poster artwork' is static and not dynamic, and is only showing the same image.

I would have thought this would have been achieved by allowing the index='n' attribute of the field to be passed a variable. This does not work. This seems odd as id='n' attribute accepts a dynamic variable.

"Back end.jpg" shows my view displaying the products associated with Content Template of the CPT 'posters'.

As you can see, I'm using a shortcode called [incrementor] that simply counts the number of elements in the view. It produces the number next to the product in the "Front end.jpg"
I would have thought that I could put this [incrementor] into the "types field" line to achieve the result I'm hoping for...

Currently:
[types field='poster-artwork' size='shop_catalog' align='none' resize='proportional' id='$current_page' index='1'][/types]

This does not work:
[types field='poster-artwork' size='shop_catalog' align='none' resize='proportional' id='$current_page' index='[incrementor]'][/types]

My result will be achieved if the index attribute can accept a dynamic variable.

Hope this is clearer.

#526932

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Jon,

Thank you for providing details.

Sorry we ran into the weekend, thank you for waiting on this. I am working on this issue and will get back to you soon with an update.

Thank you for your patience.

#526970

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Jon,

Thank you for providing details. I have understand your requirements now. The approach you are using is correct and I need to check its php code that what this [incrementor] shortcode is returning. So I need to request temporary access (WP-Admin and FTP Login info) to your site, if possible?

Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please write the name or path of the file where this shortcode’s php code is placed (e.g. functions.php).

Looking forward to help you, Thank you

#526979

I can answer that quickly.
It is returning the number 'n' you see before the product title in the "Front end.jpg" - prior to "Poster - Medium", "Coffee Mug", "Poster - Small"
Just the number on each iteration of the product render.

Yes, the incrementor shortcode function appears in "functions.php" of the child theme folder.

#526986

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Yes, I get that 🙂 But I like to take a look at the code and see what changes it need to get working. Can you please share temporary login access? I have enabled private message box.

Thank you

#527111

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

register shortcode.png

Hello Jon,

I have debugged this issue and find the cause of the problem.

1. I have registered [incrementor] shortcode in your website and now it is working as expected. Please check here: hidden link

2. Basically to use custom shortcode, you need to register the shortcode first in Toolset >> Settings >> Front-end Content >> Third-party shortcode arguments (see attached screenshot)

Thank you

#530669

Issue resolved. Thanks so much

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.