Hello everyone,
I have started developing a plugin called m2m-loop-block, which is a variation of the native WordPress Query Loop block. I'm reaching out to you both to share my work and to discuss an issue I'm facing.
Indeed, with your mb-relationship API, you require identifying the requested relationship type in correlation with the m2m relationship.
The problem is that it doesn't seem like this data is stored anywhere on the front end. However, I need access to this dataset to simply offer a dropdown list on the editor side for selecting the desired relationship type.
Here is what the current code looks like for the relevant control. The issue lies with the RELASHION_TYPE constant, as it is redundant between the backend and frontend, making it not portable:
js
import { SelectControl } from '@wordpress/components';
/**
* This is an hack because no way know to retrieve data via wordpress store.
*/
const RELATIONS_TYPE = [
{
name: 'Relation Membre vers Expertises',
slug: 'members_to_expertise'
}
]
export const PostTypeControls = ({ attributes, setAttributes }) => {
/**
* Retrieve block attributes.
*/
var { query: { id } = {} } = attributes;
if (!RELATIONS_TYPE.length) {
return <p>Chargement des types de relation...</p>;
}
/**
* Load the default value of id.
*/
if (!id && RELATIONS_TYPE.length) {
id = RELATIONS_TYPE[0].slug;
setAttributes({
query: {
...attributes.query,
id: RELATIONS_TYPE[0].slug
}
});
}
return (
<SelectControl
label="Type de relation"
value={id}
options={RELATIONS_TYPE.map(({ slug, name }) => ({
label: name,
value: slug,
}))}
onChange={ ( newRelationType ) => {
setAttributes( {
query: {
...attributes.query,
id: newRelationType
},
} );
} }
/>
);
};
If your ara in interest about the full code let me know I can publish it into public repo.