Skip Navigation

[Resolved] Conditional relationship

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 11 replies, has 3 voices.

Last updated by katjaS-3 2 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#2267677

Hi, this is going to be complicated to explain - I will try my best.

The page is a Blog for Book reviews. So I have 2 custom post types: "Book reviews" and "Book authors". They are linked by a M:N relationship.

Book reviews can have different states:
1: Book is on the shelf
2: "I am currently reading"
3: I finished reading but the book review was not created
4: review published

On one page I am showing all Book authors. But I want to filter them. I only want to show the book author if at least 1 book review is on state 4. Reason: The Book author name is linked. And the link goes to the Archiv of all Book reviews. I want to avoid "no results".

So I have created a view that shows all book review states for one book author. I have sorted the list (desc) and show only the top 1.

Now my question: how and where do I need to but the wpv-conditional to inhibit the showing.

RGDS
Frank

#2268327

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As you shared its bit complicated based on the information you shared to understand. I understand that you want to display the filtered results for book authors where book reviews status is set to 4.

Can you please share problem URL and admin access details and share all information that on that link/post what book authors should be displayed.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2269237

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've modified the view "" now so that it will return the comma separated post IDs of post type "Rezensionen" posts where custom field "Buchstatus" is set to 4. I've also check mark the checkbox "Disable the wrapping DIV around the View " on the following view:
=> hidden link

[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>
[wpv-item index=1] [wpv-post-id] [wpv-item index=other] ,[wpv-post-id]</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-no-items-found]0[/wpv-no-items-found][wpv-layout-end]

Now, I've added the post relationship filter to the view "view_autoren_fuer_buchautorenanzeige ":
=> hidden link

Beiträge in einer Rezensionen Autoren-Beziehung auswählenthat are related to the Post with ID set by the shortcode attribute wpvrelatedto.
z. B. [wpv-view name="view-name" wpvrelatedto="123"]

And then I'm displaying the view as for the first tab as given under:

[wpv-view name="view_autoren_fuer_buchautorenanzeige" von="A%" bis="D%" wpvrelatedto='[wpv-view name="view_autor_buchstatus"]']

You should try to add the attribute "wpvrelatedto" as shown above with your other tabs:

 wpvrelatedto='[wpv-view name="view_autor_buchstatus"]'

Can you please confirm it works as expected for the first tab: hidden link

If yes, you should add the attribute as I suggested above to your other tabs where you added your view "view_autoren_fuer_buchautorenanzeige".

#2269573

Unfortunately not.

I have created the page for the View 3928 "view_autor_buchstatus":
hidden link
to see what is the return. As you mentioned above. A comma separated list of all post-Ids with status=4. Without spaces.

Am I right that, that this is a kind of an array that is defined as a filter?

I have copied your statement to all tab sections. The book from "Obama" is still on status "1". Therefore as long as Obama is still in the list, the filter unfortunately does not work correctly - I am afraid.

#2269577

Update: ... I forgot to update the cache....

Now only 1 book is returned: "Shepherd, Cathrine " is the author as this was the first book that was reviewed.

#2270453

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've created the following test page and added the view to it as given under:
- hidden link

<h1> ABC </h1>
[wpv-view name='view_autor_buchstatus' von="A%" bis="D%"]


<h1> DEF </h1>
[wpv-view name='view_autor_buchstatus' von="D%" bis="G%"]

Can you please confirm that it displays the correct results:
=> hidden link

If yes, then you will have to add the view for your other character pairs at your original place where you want to display it.

I've nested the view "view_autoren_fuer_buchautorenanzeige" in side the following view:
=> hidden link

<wpv-loop>
  [wpv-view name="view_autoren_fuer_buchautorenanzeige" von="[wpv-attribute name='von']" bis="[wpv-attribute name='bis']" wpvrelatedto="[wpv-post-id]" ]
</wpv-loop>

You just have to add the view as given under for your different character ranges.

[wpv-view name='view_autor_buchstatus' von="G%" bis="J%" ]
#2272871

Hi,

sorry that din't work out, as the the example you were thankfully creating was creating a list of authors, but unfortunately unordered and with named doubled or tripled.

I was trying another approach. I would like to start with a view to the custom post type "Autoren" limited to the 2 arguments "from" "until" as before. Then I would like to set a [Condition] statement that uses a custom function as argument. I created the custom function "call view" for this. But unfortunately I capabilities for PHP coding are limited. Is there any snipped I could take as template?

#2275585

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Katja,

As Minesh is currently on vacation at the moment I will be stepping in to handle this ticket for him.

From what I understand you want to display the Parent Post only if the Child post has the status of 4 correct?

Has any of the steps that Minesh provided produced the correct results or near correct results?

Please let me know so that I can pick up from where he left off.

. Then I would like to set a [Condition] statement that uses a custom function as argument. I created the custom function "call view" for this. But unfortunately I capabilities for PHP coding are limited. Is there any snipped I could take as template?

Can you send me the custom function and explain in a bit of detail what it should be doing.

Thanks,
Shane

#2276767

Hi Shane, I must say I dont mind at all that you jump in!

Meanwhile I started learning a lot. I installed MAMP and VS Code on my PC. I duplicated my page to a localhost. So right now I am working myself into the Toolset Post relationship API. I managed to get the get_related_post function running.

My strategy is to check if the get_related_post function is not empty (So there is a post with state 4) and then I would lookup for the authors name and return this as string. So then I would not use the "condition with the custom function argument" solution anymore, but a short-code. It would be great if I could come back to you the moment I have put this together for verification or debugging. OK?

URS
Frank

#2277955

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Frank,

No problem, happy that you're making good progress and as per usual i'm here to assist whenever you run into any issues with this.

I'll also be more than happy to look over the code for you when you're through.

Thanks,
Shane

#2279033

Hi Shane,

I think now I need your help.

I created a customs PHP function inside the call-view.php and put it to the front end as shortcode.

Actually there are 3 issue, that are pretty easy for you to solve I guess.

* actually I am too stupid to hand over arguments through the shortcode. I am recieving a JSON-Error

* The result - if the argument handling would work - will not be shown inside of the Tabs-Block from where I am calling the shortcode. I have created a little test on the page "test". I wanna have several riders like "A|B|C" and "D|E|F", ... So how can I put my container inside the container of the Tabs-Block?

* I was failing to add a CHAR filter with the range a-c and so on to the WP_Query. So I created a little function and used str_starts_with - pretty much a work around? This one I dont mind too much as it would work.

THX in advance.
URS
Frank

#2280919

My issue is resolved now. Thank you!