Skip Navigation

[Resolved] List of IDs as view input

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

Problem:

Output post IDs as comma separated string.

Solution:

You can generate it using Views GUI, see screenshot:

https://toolset.com/wp-content/uploads/2019/07/toolset-views-loop-wizard-layout-options.png
option "List with separators"

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/view-layouts-101/

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
- 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/Hong_Kong (GMT+08:00)

This topic contains 16 replies, has 2 voices.

Last updated by nicolaS-3 3 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1642025

Hi,
I have two nested views returning the correct list of IDs. I need this list to feed a third view, but it comes in the following format:
24271,

24225,

24176,
instead of 24271,24225,24176, I believe due to the loop of the second view. It seems that the third view doesn't accept a list in that format in input, while it accepts a flat list (it works fine).
What can I do to remove the CRLFs to get a flat row of IDs?
Thanks
Regards
Nicola

#1642727

Hello,

How do you setup the view's loop?

You can try these:
1) In view's loop, remove all CRLFs, for example:

...
<wpv-loop >[wpv-item index=1][wpv-post-id][wpv-item index=other],[wpv-post-id]</wpv-loop>
...

2) Enable option "Disable the wrapping DIV around the View"

#1643475

Hi Luo Yang,
I did both of those in both views already, the only difference is that instead of [wpv-post-id] in one view I have the other view name, and in the other I list the child ([wpv-post-id item="@negozio-gruppo.child"],). Does this matter ?
thanks
Regards
Nicola

#1645741

I am not sure how do you setup the relationship "negozio-gruppo" and views settings.

Please provide a test site with the same problem, also point out the problem page URL and view URLs, I need to test it in a live website. thanks

#1647173

Thanks for the details, I am checking it in your website, will update here if find anything

#1647311

The CRLFs(line break) won't take effect on result, but your codes will output the result as below:
123, 456, 789,
It is ending with comma character, but views need to comma separate string, it should not be ended with comma character, like this:
123, 456, 789

I have done below modifications in your website:
1) Edit post view "1 stores", in section "Loop Editor", change the codes as below:

...
<wpv-loop>[wpv-item index=1][wpv-post-id item="@negozio-gruppo.child"][wpv-item index=other],[wpv-post-id item="@negozio-gruppo.child"]</wpv-loop>
...

2) Same as above, edit post view "2 groups", change the codes as below:

<wpv-loop>[wpv-item index=1][wpv-view name="1-stores"][wpv-item index=other],[wpv-view name="1-stores"]</wpv-loop>

Test it in front-end:
hidden link

I can see it works fine

#1648937
LY2.png

Hi,
Thanks for this, but when I pass the list of the IDs to the 3-offers-list view values from other groups are still shown and also items with no/empty relationship. Can you have a look to the 3-offers-list view to understand why the filter isn't applied ?

thanks
Regards
Nicola

#1650245

I have tried again the credentials you provided above:
https://toolset.com/forums/topic/list-of-ids-as-view-input/#post-1646403
I get these error message:

Your access to this site has been limited by the site owner

Please check it, you can also provide a copy of your website in below private message box. thanks

#1650605

Hi
for I have country limitations on please let me know where are you connecting from exactly, I have opened Hong Kong as written in your profile, is it correct ?
Thanks
Regards
Nicola

#1651157

I have tried it again, same error message, here is my Singapore IP address: 47.74.235.235

#1651337

ok, I have unblocked Singapore and whitelisted your IP, it should work now, thanks

#1651367

Thanks for the details, please check the post view "3-offers-list":
hidden link
in section "Query Filter", the relationship filter is below:
Select posts in a Gruppi-Offerte relationship that are related to the Post with ID set by the shortcode attribute gruppi.
eg. [wpv-view name="view-name" gruppi="123"]

It supports only one post ID as parameter, it does not support multiple post IDs, so it won't work as you expected.

In your case, it needs three level nested view, I have setup a demo in your website:
1) Top level post view "new 1 stores"
hidden link
- Query "Negozi" posts
- filter by the distance range
- in view's loop, display below 2nd level post view

2) 2nd level post view "new 2 groups":
hidden link
- Query "Gruppi" posts
- Filter relationship between "Negozi" and "Gruppi"
- in view's loop, display below 3rd level post view

3) 3rd level post view "new 3 offers list"
hidden link
- Query "Offerte" posts
- Filter relationship between "Gruppi" and "Offerte"
- in view's loop, display "Offerte" post infomation

Test it in front-end:
hidden link
It works fine.

#1651387

Hi
sorry, but this isn't what I was trying to achieve. This is a "normal" multiple loop stores>groups>offers that replicates results when in the user area many stores exist promoting the same group of offers. This way the user will see the same offers multiple times, and this is not good. I was trying to select/show groups of offers just once:
- 1-stores selects stores in user area
- 2-groups selects groups related to above stores but if many stores are related to the same group it returns only one group ID (any one, they all have the same group of offers) -> see limit to 1 result
- 3-offers selects all offers related to retrieved groups in 2-groups
The only solution I could find is to pass the IDs, but if you have a better one you are welcome !
One question: is there any limit in the number of IDs passed to a view?
thanks
Regards
Nicola

#1651459

Thanks for the details, in this case, it needs 4 post views
1) Use three views to get related "Offerte" post IDs:
- new 1 stores
hidden link
in section "Loop Editor", you can use [wpv-noautop] ... [/wpv-noautop] shortcode to remove extra HTML p tags.
- new 2 groups
hidden link
- New Offerte IDs
hidden link

Above nested view will be able to output all related "Offerte" post IDs as comma separated string, pass the string to below post view:

2) post view "new 3 offers list"
hidden link
- Query "Offerte" posts
- Filter by:
Include only posts with IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]
- In view's loop display the "Offerte" information

Test above view in front-end:
hidden link
will not output duplicated items.

For your reference.

#1651739

Hi Luo Yang
it's perfect, just a few questions for me to understand how it works:

1. is it the filter to act as select DISTINCT, correct ?

2. I see you prefer to use
[wpv-item index=other][wpv-view name="new-2-groups"][wpv-item index=last],[wpv-view name="new-2-groups"]
instead of
[wpv-item index=other],[wpv-view name="new-2-groups"][wpv-item index=last][wpv-view name="new-2-groups"]
Wouldn't it be better to have the comma for all others but the last one ? or is it indifferent ?

3. is there any limit to the IDs passed ? if there are many stores in the user areas can I expect issues ?

I'll close this one after this, thanks
Regards
Nicola

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