MB Relationships - m2m-loop-block plugin

Support MB Relationships MB Relationships - m2m-loop-block plugin

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #47616
    PH PrikazskyPH Prikazsky
    Participant

    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.

    #47626
    PeterPeter
    Moderator

    Hello,

    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/

    #47630
    PH PrikazskyPH Prikazsky
    Participant

    The 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.

    #47633
    PeterPeter
    Moderator

    Hello,

    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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.