MB Relationships - m2m-loop-block plugin
Support › MB Relationships › MB Relationships - m2m-loop-block plugin
- This topic has 3 replies, 2 voices, and was last updated 2 months, 3 weeks ago by
Peter.
-
AuthorPosts
-
February 7, 2025 at 9:41 PM #47616
PH Prikazsky
ParticipantHello 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.
February 9, 2025 at 9:06 PM #47626Peter
ModeratorHello,
I suggest you use the relationship Rest API to get the relationship data. Please follow the documentation https://docs.metabox.io/extensions/mb-relationships/#rest-api
However, please notice that we don't support customization code, refer to our support policy https://support.metabox.io/topic/support-policy/
February 10, 2025 at 7:11 PM #47630PH Prikazsky
ParticipantThe problem is: no way exist to retrieve the list of existing relationship name. In fact it to less time for me to write my proper REST API to retrieve the requested value than wrote to you the feature request... But it seems that feature should be included into the plugin because it depend of the table name and column name and if wrote mine it could be broken on next upgrade.
Thanks.
February 10, 2025 at 10:12 PM #47633Peter
ModeratorHello,
You can get the list of relationship IDs (type) from the table wp_mb_relationships. Please check this screenshot https://imgur.com/uU4tYMh
Then use some custom code to localize the data in the frontend and use that value. -
AuthorPosts
- You must be logged in to reply to this topic.