In a View for a custom post type, my view loop displays fields from the related posts using those related fields from the Fields and Views interface. I want to add a CSS id containing the Post ID of the related post being displayed, but there is no button for Post ID within the post type I'm displaying. How do I display the current, related Post ID in a View loop?
Hi,
Thank you for contacting us and I'd be happy to assist.
In the Fields and Views interface, you'll see the option to insert the "Post ID", in the standard WordPress fields.
( example screenshot: post-ID-fields-and-text.png )
From the next screen, you can also select the source of the relationship post type, to use for that ID.
( example screenshot: post-ID-relationship-selection.png )
That interface will add the "wpv-post-id" shortcode (ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-id) for the post ID with the item attribute ( ref: https://toolset.com/documentation/user-guides/views-shortcodes/item-attribute/ ) and you can also add the shortcode directly, for example:
[wpv-post-id item="@post-book.parent"]
In this example, the "post-book" is the relationship's slug and the "parent" part tells that the target post type is the parent in the relationship.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar