Home Forums General Issues Connect a Product page with CPT using Post Object


Connect a Product page with CPT using Post Object

  • I have been thinking about a solution for our website and would appreciate if someone could help.

    On a woocommerce site, each product can be selected with post object field to show in Custom Post Type. This CPT shows pictures of real life use of the products.

    My question is, how can a picture of a real life use automatically appear on a product page of a shown product?

    Thank you in advance

  • You need to make your field “bidirectional”, in other words, there would be a relationship post on the product page that relates the product to all the posts where it is related using the post object field on the CPT. This would likely mean updating every post. There is an explanation of doing this here and there are exiting plugins that will make relationship and post object fields bidirectional

    If the prospect of updating every post does not appeal to you then you’ll need to do a reverse relationship query when showing the product. Basically, you need to do a WP_Query() looking for any posts that have the product ID set in the field for the CPT.

    In either of the above cases you’ll need to edit the WooCommerce templates or create filters to show the information on the product page.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Connect a Product page with CPT using Post Object’ is closed to new replies.