WordPress Headless – ACF – relationship issue.

[ad_1]

Hello,

I’m working on my first project using WordPress headless and Next.js. I’m almost done, but I’ve encountered a problem. I’ve built the entire database for creating custom post types using the ACF (Advanced Custom Fields PRO) plugin. On the website, the client can add their products – it’s not an e-commerce site, just a regular informational page. Each product will have related products that should be displayed on the frontend. The client will assign these related products in the admin panel. Here’s how I implemented the functionality:

1. I created a new post type in ACF called “Products.”
2. I defined a new field group in ACF: “Product Information” – it contains fields such as a short description, *IMAGE*, a checkbox for “new” status, etc.
3. I defined another field group in ACF called “Product Blocks” – here, I used a flexible content field to build a system of blocks for various content sections on the product page, like description, gallery, etc. This way, the client can manage the content and layout of each product page.
4. I created a new layout within the flexible content field, named it “RELATED PRODUCTS,” and used the “Relationship” field to establish connections between products.

Up to this point, everything works fine. In the admin panel, the client can choose related products, and these products are fetched through the REST API and displayed on the frontend. However, I’m facing an issue:

The information about related products from the “Relationship” field in the REST API comes in a different format compared to the regular product listing. For example, the title of a product is not under the “title” key, but rather “post\_title.” I can handle this remapping on the frontend, but the problem is that the ACF fields from “Product Information” do not come through for related products. I need to display the *IMAGE* for each related product on the frontend.

I’d like to know if there’s a solution for this. Have you encountered a similar situation? If so, how do you approach handling related products?

Please advise on how to handle related products, considering the discrepancy in data format for related products from the “Relationship” field in ACF.

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer