I have created an apex class and lwc component. I have assigned profiles to the apex class for the access. In the lwc component, I have put lightningcommunity__page, lightningCommunity__Page_Layout, lightningCommunity__Default, lightning__AppPage, lightning__HomePage and lightning__recordpage as targets in js-meta.xml. In the salesforce org, the data is showing, however data is not showing in the experience cloud site. All permissions are given in OWD, read and edit permissions to the fields to the experience cloud profiles.
The problem I found is that the LWC is retrieving record ID in the salesforce org, but it is not retrieving in the experience cloud site and I think that's why the data is not showing. I have tried various ways, such as changed API version, used @salesforce/community/isCommunity, used PageReference and specified record id statically. When I specified record id statically, the data related to that record is showing in the experience cloud site. However, dynamically it is not working. What else can I try?
Then you should do what I suggested above. The {!recordId} variable should exist on a related page too.