Create Dealer Profile with archive page

Support MB Relationships Create Dealer Profile with archive page

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #30811
    PAUL TUNNICLIFFEPAUL TUNNICLIFFE
    Participant

    My site is a auto sale site, each vehicle is associated to a dealer. I'm creating front end forms so dealers can load their own inventory. Therefore a dealer also needs to be a user. The site is constructed with Metabox and elementor.

    I created a post type "dealer"

    <?php
    add_action( 'init', 'dealer_post_type' );
    function dealer_post_type() {
        $labels = [
            'name'                     => esc_html__( 'Dealers', 'gb_en' ),
            'singular_name'            => esc_html__( 'Dealer', 'gb_en' ),
            'add_new'                  => esc_html__( 'Add New', 'gb_en' ),
            'add_new_item'             => esc_html__( 'Add new dealer', 'gb_en' ),
            'edit_item'                => esc_html__( 'Edit Dealer', 'gb_en' ),
            'new_item'                 => esc_html__( 'New Dealer', 'gb_en' ),
            'view_item'                => esc_html__( 'View Dealer', 'gb_en' ),
            'view_items'               => esc_html__( 'View Dealers', 'gb_en' ),
            'search_items'             => esc_html__( 'Search Dealers', 'gb_en' ),
            'not_found'                => esc_html__( 'No dealers found', 'gb_en' ),
            'not_found_in_trash'       => esc_html__( 'No dealers found in Trash', 'gb_en' ),
            'parent_item_colon'        => esc_html__( 'Parent Dealer:', 'gb_en' ),
            'all_items'                => esc_html__( 'All Dealers', 'gb_en' ),
            'archives'                 => esc_html__( 'Dealer Archives', 'gb_en' ),
            'attributes'               => esc_html__( 'Dealer Attributes', 'gb_en' ),
            'insert_into_item'         => esc_html__( 'Insert into dealer', 'gb_en' ),
            'uploaded_to_this_item'    => esc_html__( 'Uploaded to this dealer', 'gb_en' ),
            'featured_image'           => esc_html__( 'Featured image', 'gb_en' ),
            'set_featured_image'       => esc_html__( 'Set featured image', 'gb_en' ),
            'remove_featured_image'    => esc_html__( 'Remove featured image', 'gb_en' ),
            'use_featured_image'       => esc_html__( 'Use as featured image', 'gb_en' ),
            'menu_name'                => esc_html__( 'Dealers', 'gb_en' ),
            'filter_items_list'        => esc_html__( 'Filter dealers list', 'gb_en' ),
            'filter_by_date'           => esc_html__( '', 'gb_en' ),
            'items_list_navigation'    => esc_html__( 'Dealers list navigation', 'gb_en' ),
            'items_list'               => esc_html__( 'Dealers list', 'gb_en' ),
            'item_published'           => esc_html__( 'Dealer published', 'gb_en' ),
            'item_published_privately' => esc_html__( 'Dealer published privately', 'gb_en' ),
            'item_reverted_to_draft'   => esc_html__( 'Dealer reverted to draft', 'gb_en' ),
            'item_scheduled'           => esc_html__( 'Dealer scheduled', 'gb_en' ),
            'item_updated'             => esc_html__( 'Dealer updated', 'gb_en' ),
            'text_domain'              => esc_html__( 'gb_en', 'gb_en' ),
        ];
        $args = [
            'label'               => esc_html__( 'Dealers', 'gb_en' ),
            'labels'              => $labels,
            'description'         => '',
            'public'              => true,
            'hierarchical'        => true,
            'exclude_from_search' => false,
            'publicly_queryable'  => true,
            'show_ui'             => true,
            'show_in_nav_menus'   => true,
            'show_in_admin_bar'   => false,
            'show_in_rest'        => true,
            'query_var'           => true,
            'can_export'          => true,
            'delete_with_user'    => false,
            'has_archive'         => true,
            'rest_base'           => '',
            'show_in_menu'        => true,'menu_position'       => '',
            'menu_icon'           => undefined,
            'capability_type'     => 'post',
            'supports'            => ['title'],
            'taxonomies'          => ['country'],
            'rewrite'             => [
                'with_front' => false,
            ],
        ];
    register_post_type( 'dealer', $args );
    }

    Then created a relationship to the user profile.

    <?php
    add_action( 'mb_relationships_init', 'your_prefix_function_name' );
    function your_prefix_function_name() {
        MB_Relationships_API::register( [
            'id'   => 'user-to-dealer-5if6av8w',
            'from' => [
                'object_type'   => 'user',
                'post_type'     => 'post',
                'taxonomy'      => 'category',
                'empty_message' => 'Standard user not dealer',
                'meta_box'      => [
                    'title'    => 'Related Dealer Profile',
                    'context'  => 'normal',
                    'priority' => 'high',
                ],
            ],
            'to'   => [
                'object_type' => 'post',
                'post_type'   => 'dealer',
                'meta_box'    => [
                    'style'  => 'seamless',
                    'closed' => true,
                ],
                'field'       => [
                    'max_clone' => '1',
                ],
            ],
        ] );
    }

    As I can't create an archive page of user profiles this seemed the best solution. Then when creating a post type "vehicles"

    <?php
    add_action( 'init', 'vehicles_post_type' );
    function vehicles_post_type() {
        $labels = [
            'name'                     => esc_html__( 'Vehicles', 'gb_en' ),
            'singular_name'            => esc_html__( 'Vehicle', 'gb_en' ),
            'add_new'                  => esc_html__( 'Add New Vehicle', 'gb_en' ),
            'add_new_item'             => esc_html__( 'Add new vehicle', 'gb_en' ),
            'edit_item'                => esc_html__( 'Edit Vehicle', 'gb_en' ),
            'new_item'                 => esc_html__( 'New Vehicle', 'gb_en' ),
            'view_item'                => esc_html__( 'View Vehicle', 'gb_en' ),
            'view_items'               => esc_html__( 'View Vehicles', 'gb_en' ),
            'search_items'             => esc_html__( 'Search Vehicles', 'gb_en' ),
            'not_found'                => esc_html__( 'No vehicles found', 'gb_en' ),
            'not_found_in_trash'       => esc_html__( 'No vehicles found in Trash', 'gb_en' ),
            'parent_item_colon'        => esc_html__( 'Parent Vehicle:', 'gb_en' ),
            'all_items'                => esc_html__( 'All Vehicles', 'gb_en' ),
            'archives'                 => esc_html__( 'Vehicle Archives', 'gb_en' ),
            'attributes'               => esc_html__( 'Vehicle Attributes', 'gb_en' ),
            'insert_into_item'         => esc_html__( 'Insert into vehicle', 'gb_en' ),
            'uploaded_to_this_item'    => esc_html__( 'Uploaded to this vehicle', 'gb_en' ),
            'featured_image'           => esc_html__( 'Featured image', 'gb_en' ),
            'set_featured_image'       => esc_html__( 'Set featured image', 'gb_en' ),
            'remove_featured_image'    => esc_html__( 'Remove featured image', 'gb_en' ),
            'use_featured_image'       => esc_html__( 'Use as featured image', 'gb_en' ),
            'menu_name'                => esc_html__( 'Vehicles', 'gb_en' ),
            'filter_items_list'        => esc_html__( 'Filter vehicles list', 'gb_en' ),
            'filter_by_date'           => esc_html__( '', 'gb_en' ),
            'items_list_navigation'    => esc_html__( 'Vehicles list navigation', 'gb_en' ),
            'items_list'               => esc_html__( 'Vehicles list', 'gb_en' ),
            'item_published'           => esc_html__( 'Vehicle published', 'gb_en' ),
            'item_published_privately' => esc_html__( 'Vehicle published privately', 'gb_en' ),
            'item_reverted_to_draft'   => esc_html__( 'Vehicle reverted to draft', 'gb_en' ),
            'item_scheduled'           => esc_html__( 'Vehicle scheduled', 'gb_en' ),
            'item_updated'             => esc_html__( 'Vehicle updated', 'gb_en' ),
            'text_domain'              => esc_html__( 'gb_en', 'gb_en' ),
        ];
        $args = [
            'label'               => esc_html__( 'Vehicles', 'gb_en' ),
            'labels'              => $labels,
            'description'         => 'Classified listing of vehicles for sale.',
            'public'              => true,
            'hierarchical'        => true,
            'exclude_from_search' => false,
            'publicly_queryable'  => true,
            'show_ui'             => true,
            'show_in_nav_menus'   => true,
            'show_in_admin_bar'   => true,
            'show_in_rest'        => false,
            'query_var'           => true,
            'can_export'          => true,
            'delete_with_user'    => false,
            'has_archive'         => true,
            'rest_base'           => '',
            'show_in_menu'        => true,'menu_position'       => 25,
            'menu_icon'           => undefined,
            'capability_type'     => 'post',
            'supports'            => ['title', 'author'],
            'taxonomies'          => ['emmission-level', 'vehicle_type_tax', 'make_model_tax', 'make_model_body_tax', 'exterior_extra_feature_tax', 'interior_extra_feature_tax', 'exterior_colour_tax', 'interior_colour_tax', 'transmission_tax', 'drive_tax', 'fuel_tax', 'emmission_level_tax', 'emission-level', 'drive', 'exterior-extra-feature'],
            'rewrite'             => [
                'with_front' => true,
            ],
        ];
    register_post_type( 'vehicles', $args );
    }

    It becomes associated to the dealers user profile, by the relationship is would also be related to the associated dealer post type.

    however can I show data on each vehicle listing from the dealer post type as its a 2 step relationship?

    I do appreciate this could also be solved if the user profile could be added to a archive page if a custom switch field was "Make Public" - on. However there doesn't seem a way to associate an archive page to a user profile (conditionally) with elementor.

    All help and feedback appreciated!!

    #30816
    Long NguyenLong Nguyen
    Moderator

    Hi Paul,

    Currently, Elementor does not support showing the relationship posts. You need to use the code to create the template, or a shortcode to the relationship posts.

    Refer to the documentation https://docs.metabox.io/extensions/mb-relationships/
    and this topic https://support.metabox.io/topic/displaying-2-custom-post-types-via-a-relationship-custom-post-type/

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