Skip Navigation

[Resolved] Showing images using a view shortcode with the current post id as a filter

This support ticket is created 3 years, 10 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 10 replies, has 2 voices.

Last updated by Christian Cox 3 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1656143

I've got a custom post type that has a repeating image field that I want to display as an image gallery on the frontend content template.

To do so I've built a view that displays the images and have set a Post ID Filter to use a shortcode attribute.

Here's what my view shortcode looks like in the content template:

{!{wpv-view name='photo-gallery-2021' tripid='{!{wpv-post-id}!}'}!}

I'd like tripid to use the post id of the current post (hence the wpv-post-id shortcode). If there's a better way to do this please let me know.

I have two issues:

1. When displaying the frontend template, the same images show on each different post regardless of their post id, so it looks like either the view is being cached or the Post ID is somehow hardcoded into the template instead of coming from the shortcode.

2. At the end of the gallery '/] is shown even though there isn't any extra closing brackets on the shortcode. If I remove the last }!} the gallery still displays on the frontend and the '/] isn't there, but something doesn't feel right about leaving it open like that.

Appreciate all the help you can provide.

#1656291

2. At the end of the gallery '/] is shown even though there isn't any extra closing brackets on the shortcode. If I remove the last }!} the gallery still displays on the frontend and the '/] isn't there, but something doesn't feel right about leaving it open like that.
I think the nested curly bracket shortcodes are causing a rendering problem. Try this version:

{!{wpv-view name='photo-gallery-2021' tripid='[wpv-post-id]'}!}

Are you using a page builder that requires the curly bracket shortcode notation? If so, which one? If not, square brackets should be fine.

1. When displaying the frontend template, the same images show on each different post regardless of their post id, so it looks like either the view is being cached or the Post ID is somehow hardcoded into the template instead of coming from the shortcode.
I think the nested shortcode issue above may have been contributing to this problem. If you still experience the problem after updating the shortcode, place the wpv-post-id shortcode just before the View shortcode and confirm that the post ID is what you expect to find here:

Post ID: {!{wpv-post-id}!}<br />
{!{wpv-view name='photo-gallery-2021' tripid='[wpv-post-id]'}!}

If the ID is correct, then the issue may be in the post ID Query Filter settings. Please edit the view, open the post ID Query Filter panel, and take a screenshot of the configurations for this filter. If you cannot see the Query Filter panel, scroll up to the top right corner and click "Screen Options" to expose the panel. Share the screenshot in your next reply and I'll take a look at everything.

#1657693
Screen Shot 2020-06-10 at 8.35.35 PM.jpg
Screen Shot 2020-06-10 at 8.35.29 PM.jpg
Screen Shot 2020-06-10 at 8.35.01 PM.png

Thanks Christian.
We're using WPBakery & it doesn't seem to matter whether we use curly or square braces, both issues are still there even after trying your suggested version. The only difference is with your version it shows '] at the end instead of '/].

I've attached screenshots of the Query Filter panel as well as two different posts that show the same photo gallery despite the post ID being different in each. The gallery view is being called using your version of the shortcode from above.

#1658715

May I log in to your wp-admin area and take a closer look at how this is set up? Please provide login credentials in the private reply fields here.

#1663439

Okay thanks, it seems like the WP Bakery interface doesn't recognize the nested shortcode no matter what I try. Let me run some tests and try to reproduce that locally.

#1663519

Okay, I can confirm shortcodes as shortcode attributes are not respected in my local tests, so I will escalate the problem to my 2nd tier support team for additional investigation. I'll let you know what I find out.

#1663779

Thanks Christian, appreciate you tackling this.

#1667339

Just checking in on this to see if there's anything new. Thanks.

#1667357

Hi, I've submitted this to my 2nd tier team but they had some problems reproducing the issue. I've created a clone of my test site so they can see the issue more clearly. I hope to receive their feedback tomorrow, since that team member is in a European timezone and their shift has ended. In the meantime, I might be able to show you an alternative solution that works right now. Can you provide some details about why you decided to use a View in this situation? You could insert the gallery block directly in a Toolset Content Template using the Block Editor, then place that Content Template in your WPBakery template using a wpv-post-body shortcode instead of adding a View. Since the images you want to display are pulling from the current post, the post context should be maintained without the need for a View and post ID Query Filter. Of course, for flexibility, I understand why a View would be ideal. You could reuse a View in other areas and choose to display images from any post dynamically, but in this particular situation it doesn't seem to be a requirement. I'd appreciate your thoughts on this.

#1674015

Hi, I'm going through my queue of pending escalated threads and noticed that I have not yet received feedback about this from my second tier team. I have asked again for an update, and expect to get some by tomorrow. Until I hear back from them, did you have time to consider my question? Basically I wanted to know more about why you chose to add a View in your Toolset Content Template instead of placing the gallery block directly in the Toolset Content Template.

#1675125

I got some feedback from the team, and we have found that switching from a Raw HTML block to a Text block resolves parsing issues when using Toolset shortcodes as Toolset shortcode attributes. With that in mind, I updated my clone of your site locally and was able to see the correct images appear in the template, and the extra closing bracket code was also resolved. Please try using a Text Block instead of the Raw HTML block and let me know if the issue is not resolved. I'm using the square bracket notation locally without any problems, so I suggest you do the same.

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