I have a one-to-many relationship setup between the two post types.
One: "Auction Page"
Many: Products
Let's say I have a single Auction Page which is linked with Product A, and Product B.
What PHP code should I be using in my template file to get the ID of the parent Auction Page if the code is being display on the Product pages?
My goal is to create a button on the product pages that links back to the parent Auction page. So I need the ID to pass to the permalink function.
I am using the latest version of toolset, but the examples in the documentation have not been helpful: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
After playing around with the code I finally found a working solution. Here is the snippet I used.
$product_id = get_post( get_the_ID() ); // Get ID of current product
$auction_parent_page_id = toolset_get_related_post( // Get ID of parent auction page
$product_id,
'auction-page-product', //slug of relationship
'parent'
);
Then I was able to pass $auction_parent_page_id to the get_the_permalink() function to output my link correctly.