Hi there.
I seem to be having trouble displaying conditional parent post content with the new relationships set up.... Hoping you can advise. So far, I have not been able to make anything work...
To give you an idea of setup, I have the following established:
Parent: event
Child: event-date
Relationship One to Many: event_event-date
Note: It is not possible for an event-date to exist without belonging to a parent event so there are NO event-date posts that do not belong to an event parent. Also to note that all plugins, wordpress, theme and translations are up to date and have been tested for conflicts.
In a view displaying 'Event Dates' I want to display, within the loop template, the parent post 'Event' image field if it is NOT EMPTY and if it is EMPTY something else.
I have tried all of the following support advice and still can't make anything work:
https://toolset.com/forums/topic/content-should-be-empty-if-no-parent-relationship/
https://toolset.com/forums/topic/conditional-display-if-parent-is-a-certain-post-type/
https://toolset.com/forums/topic/managing-display-of-parent-custom-fields-and-rfg-in-childs-content-template/
https://toolset.com/forums/topic/conditional-if-a-parent-post-exists-and-its-custom-field-is-not-empty-then/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-types-fields-and-custom-fields/
https://toolset.com/forums/topic/conditional-output-with-parents-custom-fields/
In summary of all the above ideas I am presuming something like this, however, this does not work:
[wpv-conditional if="( '[types field='event-featured-image' item='@event_event-date.parent'][/types]' ne '' )"]
DISPLAY IMAGE TAG
[/wpv-conditional]
[wpv-conditional if="( '[types field='event-featured-image' item='@event_event-date.parent'][/types]' eq '' )"]
DISPLAY SOMETHING ELSE
[/wpv-conditional]
Look forward to hearing from you!
Regards
Rita
You need to set up conditionals with the GUI, manually this likely will not work as you will have to guess the slugs.
Also, Featured Images cannot be evaluated like that.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/#checking-if-a-post-has-a-featured-image
I think this is the core issue of the problem you report.
If you set it up as above shown on that DOC, it should work.
Hi Beda!
Thanks for the quick response. Appreciated.
The field is not the wordpress feature image.
Its a types custom field with slug: wpcf-event-featured-image
So do you mean to say it is not possible with the new relationships tables?
If it is a Toolset Types Image Field, you can simply check for its emptiness like so:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/#2-comparing-the-element-with-an-empty-string
If you want to check up on a field of a related post you can use the ID attribute, which is also available in the GUI when you insert the shortcode to evaluate.
Note that you cannot target related items of a Many To Many Relationship like this because there might be many items, and the ID attribute does not know which item you mean in this case (as there are many)
However, if it's a one to- or many to- one then you can simply query the many parts of the relationship in the View and check up on it's (single) parent with the ID attribute.
If you cannot make it work, can you indicate me the precise View and the field you want to check upon, and provide some Access to the website?
Then I can have directly a look and put an example in there!
Hi Beda
Yes, I have tried all these ideas...
I think there is a problem. In general I use this on most views for most posts which is working fine:
[wpv-conditional if="NOT( empty($(custom-field-slug)) )"]
image
[/wpv-conditional]
[wpv-conditional if="NOT( empty($(custom-field-slug)) )" evaluate="false"]
something else
[/wpv-conditional]
For views showing parent custom fields of the current post in a one to many relationship I am using the new gui. Here an example:
[wpv-conditional if="( $(wpcf-event-featured-image).item(@event_event-date.parent) ne '' )"]
image
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-event-featured-image).item(@event_event-date.parent) ne '' )" evaluate="false"]
something else
[/wpv-conditional]
For some reason this doesn't work on one post and its children...
I need to get my head round what's going on... I am trying to make old posts and old relationships work together with new posts and new relationships... and all work together in your new relationships tables. (I regret migrating...) so it could be an error on my part... Or it could be that it's just not poss to make it all work together.
Will come back to you... Thank you for your time!