Skip Navigation

[Resolved] Using shortcode attribute in Views content selection

This support ticket is created 3 years, 2 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

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

This topic contains 6 replies, has 2 voices.

Last updated by jesperA-2 3 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2200551

Tell us what you are trying to do? I have a view which should show results filtered by a relation ID. However, there could be several IDs. So I figured I could use a shortcode ("The post with ID set by the shortcode attribute") and return a string with several IDs.
Like "1,2,3". I try to use the Blocks attributes to do this (so using the UI). However the filter doesn't work. All posts are displayed.
Shouldn't this be possible or have I missed something?

Is there any documentation that you are following? I've checked this: https://toolset.com/course-lesson/displaying-related-posts/?utm_source=plugin&utm_medium=gui&utm_campaign=blocks
but it didn't answer my questoin.

Is there a similar example that we can see?

What is the link to your site?

#2201253

Hi,

Thank you for contacting us and I'd be happy to assist.

On my test website, I was able to make this filtering work, using the following steps:

1. I created a new page and created a new view to show posts, with a post ID query filter, linked to the shortcode attribute.
( screenshot: hidden link )

2. Next, on the actual page where I wanted to show this view, I inserted the view block and selected the view from the step 1, as the existing view.

3. In this view block's settings, I entered the comma-separated list of target post IDs and it worked.
( screenshot: hidden link )

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2201323
Skärmavbild 2021-10-21 kl. 08.54.38.png

I created a new page & view. Same result. I think what's important here is that I try to filter the result with IDs from a RELATIONSHIP. So it's not just a matter of postIDs for the current posts in the view but instead for it's relationship (see included image).

When I try to set each relationship separately (with the "Specific" choice) it works. But when I try to combine two comma separated IDs (returned correctly by the shortcode) it just ignores the filtering altogether.
I can give access to the site if necessary (not to public).

#2201423

Hi, I found this post: https://toolset.com/forums/topic/passing-multiple-arguments-to-views/
Seems it's not possible using the UI for several IDs but could be done with some custom code?
There's a hidden link to an example in the linked article I can't see.

#2202767

Hi, I managed to solve this problem using by using wpv_filter_query. It's fine to use code for more complex filtering but it would be nice to connect this code to the view on the page somehow (to keep track of what code is affecting the current view).

And I would suggest (hope) you add the ability to have a shortcode which returns multiple IDs in the blocks view query filter UI as well. It's seems natural do have it there and don't have to mix code and the UI blocks (and I'm not the only one wanting this).

#2202769

Hi, I managed to solve this problem using by using wpv_filter_query. It's fine to use code for more complex filtering but it would be nice to connect this code to the view on the page somehow (to keep track of what code is affecting the current view).
And I would suggest (hope) you add the ability to have a shortcode which returns multiple IDs in the blocks view query filter UI as well. It's seems natural do have it there and don't have to mix code and the UI blocks (and I'm not the only one wanting this).

#2202771

Hi, I managed to solve this problem using by using wpv_filter_query. It's fine to use code for more complex filtering but it would be nice to connect this code to the view on the page somehow (to keep track of what code is affecting the current view).

And I would suggest (hope) you add the ability to have a shortcode which returns multiple IDs in the blocks view query filter UI as well. It's seems natural do have it there and don't have to mix code and the UI blocks (and I'm not the only one wanting this).