Support

Account

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

Helping

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 https://www.advancedcustomfields.com/resources/bidirectional-relationships/ and there are exiting plugins that will make relationship and post object fields bidirectional https://www.google.com/search?q=acf+budirections+relationship

    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. https://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/

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.