I am trying to: display the number of people a barn sleeps
Link to a page where the issue can be seen: hidden link
I expected to see: Sleeps: 2
Instead, I got: Sleeps:
I have 2 post types (Barns and Late Availability) which have been linked (many-to-many relationship).
The view should pull in the number of people the barn sleeps but doesn't. The field is available for me to include in the 'Loop Items' but nothing is actually displayed. My loop:
Thank you for contacting us and I'd be happy to assist.
In your view named "Lates", the following shortcode was being used to get the value from the "sleeps" custom field.
[types field="sleeps"][/types]
But this wasn't returning any value because this custom field value is saved with the "Barn" posts and not with the "Late Availability" posts which are being called through this view.
To get this field's value from the child "Barn" post, you'll need to introduce the "item" attribute, like this:
Important note:
This item attribute method will only get information from one of the related posts. Since the relationship "Late Availability Barns" is set to be of type "Many-to-Many", more than one "Barn" posts can be attached to a single "Late Availability" post.
Thanks for writing back and yes it would be better to switch to a "one-to-many" type post-relationship in this case.
( where one barn can have many offers, but one offer can only have one barn )
Some post associations can be lost when the type of an existing post-relationship is changed. Since your website doesn't have a lot of barn and offer posts at this time, I'll recommend to delete the existing post-relationship and create a new one and make the associations again.
Thanks for your further advice, Waqar. I ended up deleting the relationship because not only should it have been a 'one-to-many' relationship, but the two custom posts needed to be the other way round (swapping parent and child). After rebuilding it afresh, adjusting the Views codes where necessary , it all seems to work well. Best wishes, Josh.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.