Custom Fields
Re-Envisioned
Support MB Relationships CPTs with Taxonomies Relationship

  • Creator
    Topic
  • #23419
    Resolved Scot MacDonald
    Participant

    Hi

    New user, impressed already.

    I have a CPT called Profile that I want users to create and while doing so will add skills (a taxonomy of Profile but also three additional CPTs called Occupation, Industry and Program).

    I want to be able to display “related” occupations, industries and training programs in the sidebar of a Profile (in cases where individual posts of those CPTs have the same skills).

    What relationship should I be using here? This is what I believed to be correct for a relationship between Skills and Occupations but it doesn’t seem to be working.

    add_action( 'mb_relationships_init', function () {
        MB_Relationships_API::register( [
            'id'   => 'skills_to_occupations',
            'from' => [
                'object_type' => 'term',
                'taxonomy'    => 'skill',
            ],
            'to'   => 'occupation',
        ] );
    } );

    Appreciate any assistance you can provide.

    Thanks

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #23420
    Long Nguyen
    Moderator

    Hi Scot,

    Here is the sample code to connect a taxonomy to a CPT

    add_action( 'mb_relationships_init', function () {
        MB_Relationships_API::register( [
            'id'   => 'skills_to_occupations',
            'from' => [
                'object_type' => 'term',
                'taxonomy'    => 'skill',
            ],
            'to'   => [
                'object_type' => 'post',
                'post_type'   => 'occupation',
            ],
        ] );
    } );

    Get more details here https://docs.metabox.io/extensions/mb-relationships/#users-to-posts

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.