CPTs with Taxonomies Relationship

Support MB Relationships CPTs with Taxonomies RelationshipResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #23419
    Scot MacDonaldScot 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

    #23420
    Long NguyenLong 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 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.