Navigation überspringen

[Gelöst] Split: Condition in View that depends on intermediary post – QUESTION 1

This support ticket is created vor 4 Jahren, 4 Monaten. 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: Africa/Casablanca (GMT+01:00)

Dieses Thema enthält 50 Antworten, hat 3 Stimmen.

Zuletzt aktualisiert von AlimB3245 vor 4 Jahren, 3 Monaten.

Assistiert von: Jamal.

Author
Artikel
#1776699

Hi Jamal

Any update on this?

Regards,
Alim

#1778601

Hello Alim, it took me a long time to come up with a partial solution. Why is it partial? Consider the following screenshot versteckter Link
This solution will not return a URL for both cases(when the user store is "in" or "ae").
When the user store is "ae", the distributor is also assigned "in", so it should not return a URL. That's what I understood from your earlier messages.
But, when the store is "in", it will add complexity to get only "Ronak Optik" and omit "FourPlus Vision".

I hope that's OK.

The solution consists of different content templates, views, and some custom code.

First, let's agree on how content templates work. A content template needs to have a context, the context is the post that this content template will display. You can pass a different context to a content template using the item argument of the wpv-post-body shortcode.

In this solution, we pass contexts to some content templates using the item argument and the Toolset relationships.

I was working on this content template versteckter Link with ID 46475
In order to preview it on a post we add "?content-template-id={ID}". You can preview the solution for the reference Eyewear collection here versteckter Link
Please login with the user Optician.

This content template uses a custom shortcode get_ec_store_for_user to get the "URL". The shortcode expects a brand and a user store. We pass the brand using Toolset relationships and the store using user meta shortcodes:

[get_ec_store_for_user brand='[wpv-post-id item='@eyewear-brand-eyewear-collection.parent']' store='[wpv-user field='wpcf-user-store' output='raw']']

The shortcode will use a view to get the list of intermediary posts, with their titles and the store field. The title is then used to get the distributor ID. Then we pass it to a content template to build the URL.
The view: versteckter Link
The content template: versteckter Link

We use some separators that are unlikely to be part of your data, such as (|) and multiple commas(,,,).

Please change the user store for "optician" and check the expected results here versteckter Link

I hope this helps. Let me know if you have any questions.

#1780843

Hi Jamal

Thanks for your efforts and I really appreciate all that your putting into this..:-)..

This solution will not return a URL for both cases(when the user store is "in" or "ae").
When the user store is "ae", the distributor is also assigned "in", so it should not return a URL. That's what I understood from your earlier messages.
But, when the store is "in", it will add complexity to get only "Ronak Optik" and omit "FourPlus Vision".

when you say 'not return a URL' you mean it won't get me the 'value for the variable'... am I right?
Because I am creating a URL based on variables and I am getting the values for these variables using toolset functions.. so I've managed to get the values for the others and I wanted to get the bo-id, bo-name,bo-email,bo-mobile (and one more order-notification)

So just wanted to ensure if you've got the requirement right..
When the USER STORE is AE
The DISTRIBUTOR ASSIGNED to AE should returned (and we get the values of id,name,etc from here)

AND IF there are MULTIPLE distributors returned for AE, then values should become NULL

Please do confirm if your code is achieving this.. so that we don't head in the wrong direction.. because I was confused about 'returning the URL'.. it might have a different meaning for you and different meaning for me..;-).. for me the URL is the one I have already created as a link when you click on Purchase Inventory.. is it the same for you? Because to me, there's no question of not returning the URL.. the URL will always be there.. but yes, the values in URL may or may not exist based on if toolset functions return them or not...

Apologies for the delay in responding.. I realised that the notification setting for this ticket was OFF and I just put it ON again.. will do the tests as you have suggested but I'd request you to check the above and confirm if we are both on the same page on this..;-)..

Regards,
Alim

#1780849

Hi Jamal

I tested it logged in as 'optician' with user-store as 'in' and I got the URL below.. you will notice the bo-id, bo-name etc are blank

versteckter Link;

Similarly I tested it logged in as 'optician' with user-store as 'ae' and I got the URL below.. you will notice the bo-id, bo-name etc are blank again

versteckter Link

So I don't think it's working.. but I have a feeling you are trying to do something else.. that's why I was trying to understand the 'return the URL' statement.. please do advise..

Regards,
Alim

#1781725

when you say 'not return a URL' you mean it won't get me the 'value for the variable'... am I right?
Yes, I meant that we won't get the ID of the distributor who met the criteria. And it will return an empty string.

I am aware this does not fulfill your use case exactly (return null for the fields' values), and as I explained, all my tests were done on the content template "Eyewear Collection - Inventory URL - Legacy editor" with ID 46475.

The solution uses several parts:
- A custom shortcode.
- A view.
- A content template to build the final URL. The content template is versteckter Link
Unfortunately, the content template was reset because the URL I shared(it contained &reset=true)
I added a couple of shortcodes to demonstrate what distributor we have got.

Check this page with the "optician" user versteckter Link
Here a screenshot versteckter Link you will see that all fields are returned except bo-name, which we try to get with the following shortcode:

[types field='organisation-name'][/types]

Maybe the custom field slug has a typo or is different.

This page is rendered using the "Eyewear Collection - Inventory URL - Legacy editor" content template, just for testing. You can check this content template to see how the shortcode is used.

The URL is built using the following content template, only, if a distributor is found versteckter Link
As you can see in the custom code at line 60, we are passing the ID of the distributor to the content template. But if we don't find a distributor the shortcode simply returns an empty string.

Please check the custom shortcode code, I added comments to it to explain each step. You can adapt the custom shortcode code to exactly suit your need. Replace each return of an empty string with the desired outcome.
The provided solution is primarily to explain how you can achieve the expected result with the minimal custom code possible. I am sure you will understand that we are limited in the amount of custom code support we can offer.

Check the content template "Distributor URL" to see how the URL is built. Then check the content template "Eyewear Collection - Inventory URL - Legacy editor" to see how the shortcode is being used.
Then update the code of your "Inventory button" to use the shortcode for the parts of the URL that we need to get from the Distributor.

I hope, you understand, how we built this solution. That's important to let you use it and get inspired for other cases where intermediary posts are involved.

#1782075

Hi Jamal

It's a bit difficult for me to grasp what is being explained and I think I will open a new ticket and if possible please take me step by step on that one.. I'll first start by displaying a grandparent field.. that's where I was stuck initially and I managed to get a post title.. I'd like to first manage to get a field form a grand-parent post.. before I try to get into the complicated stuff..;-)..

Regards,
Alim