Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Last active December 8, 2023 08:22
Show Gist options
  • Save Crocoblock/102314ceabe4e6759e1ff196f1d91079 to your computer and use it in GitHub Desktop.
Save Crocoblock/102314ceabe4e6759e1ff196f1d91079 to your computer and use it in GitHub Desktop.
JetEngine Relations: update items programmatically, register a relation programmatically
<?php
add_filter( 'jet-engine/relations/raw-relations', function( $relations ) {
$relations[999] = array(
'name' => 'User to post',
'parent_rel' => null,
'type' => 'many_to_many',
'is_legacy' => false,
'id' => 999,
'parent_object' => 'mix::users',
'child_object' => 'posts::post',
'parent_control' => true,
'child_control' => true,
'parent_manager' => true,
'child_manager' => true,
'parent_allow_delete' => true,
'child_allow_delete' => true,
'rest_get_enabled' => true,
'rest_post_enabled' => true,
'rest_get_access' => 'manage_options',
'rest_post_access' => 'manage_options',
'labels' => array (
'name' => 'User to post',
'parent_page_control_title' => 'Posts, connected to the user',
'parent_page_control_connect' => 'Connect posts',
'parent_page_control_select' => 'Select posts',
'child_page_control_title' => 'Users, connected to the post',
'child_page_control_connect' => 'Connect users',
'child_page_control_select' => 'Select users',
'child_page_control_create' => 'Create user',
'parent_page_control_create' => 'Create post',
),
);
return $relations;
} );
//relation with meta fields and CCT-specific controls
add_filter( 'jet-engine/relations/raw-relations', function( $relations ) {
$relations[1000] = array (
'id' => '1000',
'db_table' => true,
'parent_control' => true,
'child_control' => true,
'parent_manager' => true,
'child_manager' => true,
'parent_allow_delete' => true,
'child_allow_delete' => true,
'is_legacy' => false,
'rest_get_enabled' => true,
'rest_post_enabled' => true,
'name' => '',
'parent_object' => 'cct::blum_cct',
'child_object' => 'posts::blum-cpt',
'parent_rel' => NULL,
'type' => 'many_to_many',
'legacy_id' => '',
'rest_get_access' => 'manage_options',
'rest_post_access' => 'manage_options',
'cct' =>
array (
'cct::blum_cct' =>
array (
'title_field' => 'f1',
'create_fields' =>
array (
'f2',
'rep_test',
'num3',
'num1',
),
),
),
'labels' => array (
'name' => 'cct to cpt',
'parent_page_control_title' => 'Parent Object: label of relation box',
'parent_page_control_connect' => 'Parent Object: label of connect button',
'parent_page_control_select' => 'Parent Object: label of select item control',
'parent_page_control_create' => 'Parent Object: label of create button',
'child_page_control_title' => 'Child Object: label of relation box',
'child_page_control_connect' => 'Child Object: label of connect button',
'child_page_control_select' => 'Child Object: label of select item control',
'child_page_control_create' => 'Child Object: label of create button',
),
'meta_fields' =>
array (
array (
'title' => 't1',
'name' => 't1',
'object_type' => 'field',
'width' => '100%',
'options' => array (),
'type' => 'text',
),
array (
'title' => 't2',
'name' => 't2',
'object_type' => 'field',
'width' => '100%',
'options' => array (),
'type' => 'text',
),
),
);
return $relations;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment