Tell us what you are trying to do?
I want to Display fields of post relationships in views in classic editor
I have two custom post types: "Termine" and "Personen", they are connected as many-to-many post relationships
Now I want to display in "Termine" a custom field of connected "Personen", named "Funktion".
I did not find a doc to do this in the classic editor. I guess I have to use a view because there are several "Personen" connected with one "Termine".
I managed to display one title (wpv-title) of one connected "Personen", but failed to list all connected "Personen". The next step would be to get access to the custom field"Funktion" of "Personen".
Is there a doc for this?
Is this possible with many-to-many post relationships or do I need post reference fields?
Is there any documentation that you are following?
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/
-> but this is only for Block editor
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/using-post-reference-fields-to-display-information-from-a-related-post/
- I don't know if I need this, because I have set up post relationships
What is the link to your site?
versteckter Link
You could create a view that queries the Intermediate Post Type.
Set the Query Filter of that view returning posts in the relationship you use, of the post where the View is inserted to.
In the View Loop, you can insert the usual ShortCodes for data - passing the "item" attribute you can decide which related post data to display.
Since Intermediary posts are unique for each relationship, even if you have many related posts on one post, this allows to create a list of all intermediary posts and call their other related post (which is as well always unique).
Example:
1. The relationship is "the-relationship", with an Intermediary Post "the-relationship-intermediary" between pages and posts
2. Create a few related posts
3. Create a View, query the intermediary posts type
4. Output in the loop something like this: [wpv-post-title item="@the-relationship.parent"]
5. Insert this View to a Page where you have related posts added.
Similarly, you can call Fields of those related posts, using the GUI you can always choose what data to display for the ShortCodes you insert.
Great, thank you Beda. This has helped me to go further. I was stuck at number 3. "query the intermediary posts type" in the list view.
Now I got the output loop with items like:
[wpv-post-title item="@termin-veranstalter.child"]
Email: [types field='email-veranstalter' item="@termin-veranstalter.child"][/types]
Now I need a condition in the output loop. I want the line with Email:... only if there is an email address. Using the loop assistant for conditions, I only get fileds from the current post, not from relationships like this:
versteckter Link
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/conditional-output-based-on-post-relationships/
My condition looks like this and does not work:
[wpv-conditional if="( $(wpcf-email-veranstalter) eq '' )"]Email-Veranstalter: [types field='email-veranstalter' item="@termin-veranstalter.child"][/types]<br>[/wpv-conditional]
I attach a screenshot of the condition assistant.
Can I put the relationship manually into the condition?
Regards,
Jürgen
You can use HTML Conditional for this:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/
However, you'll need to manually update your HTML Condition after inserting it to define the precise data to compare.
You can simply insert the ShortCode with a chek on th "post title" shortcode and then remove that [wpv-post-title] and substitute that with the proper shortcode you want to compare to.
Pay attention to nested "" apostrophes in the conditional, replace them with single '' when "inside" the condition and use "" only "outside" the conditional.
Example
[wpv-conditional if="( '[wpv-post-title item='@the-relationship.parent']' ne '' )"]
Has data
[/wpv-conditional]
thank you Beda, nearly got it...
This works:
[wpv-conditional if="( '[wpv-post-title item='@termin-veranstalter.child']' ne 'ALEGRIA' )" debug="true"][wpv-post-title item="@termin-veranstalter.child"]<br>[/wpv-conditional]
But I need to check a field (and later some more) in the conditional. The following does not work:
[wpv-conditional if="( '[types field='email-veranstalter' item='@termin-veranstalter.child'][/types]' ne '' )" debug="true"] Email-Veranstalter1: [types field='email-veranstalter' item="@termin-veranstalter.child"][/types]<br>[/wpv-conditional]
The debug output is:
####################
wpv-conditional attributes
####################
Array
(
[if] => ( '' ne '' )
[debug] => true
)
####################
Debug information
####################
--------------------
Original expression: ( '' ne '' )
--------------------
After replacing 1 general variables and comparing strings: ( '' ne '' )
Comparing to
Any idea what I can do now?
I also studied https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/ cannot see the solution.
Regards
Jürgen
the funny thing is in another view of another post relationship it does work:
[wpv-conditional if="( '[types field='funktion' item='@termin-person.child'][/types]' eq 'Dirigent' )"]
[types field='funktion' item='@termin-person.child'][/types]: [wpv-post-link item='@termin-person.child']<br>[/wpv-conditional]
Happy Easter!
My issue is resolved now. Thank you!
The solution:
I have to use output='raw' in fields with email addresses and website-urls:
[wpv-conditional if="( '[types field='email-veranstalter' output='raw' item='@termin-veranstalter.child'][/types]' ne '' )"]