Changing default title of relationships box
- This topic has 4 replies, 2 voices, and was last updated 3 years, 11 months ago by
@mindspark.
-
AuthorPosts
-
May 10, 2021 at 9:33 PM #28072
@mindspark
ParticipantI'm making some relationships between several CPTs and custom Taxonomies. When we make these relationships - we see the box on the right side of the screen and it says 'Connected From' or 'Connected To'. See here: https://snipboard.io/vxMdPb.jpg
I would like to change these titles. Is that possible? and if so, can I assign unique titles to different boxes so they don't all read the same?
thanks for your help.
May 11, 2021 at 12:47 PM #28081Long Nguyen
ModeratorHi,
Yes, it is possible. You can add the setting meta box title to the
from
orto
array. For example:'from' => [ 'object_type' => 'post', 'post_type' => 'post', 'meta_box' => [ 'title' => 'Custom connected' ] ], 'to' => 'page',
Read more on the documentation https://docs.metabox.io/extensions/mb-relationships/#syntax
If you use the builder, you can click on the tab Meta Box, screenshot https://share.getcloudapp.com/P8u5qJYl.
May 11, 2021 at 8:10 PM #28098@mindspark
ParticipantYour code example isolates the type of relationship (posts to posts, terms to posts, etc). But what if I wanted to isolate by specific relationship?
Example, I have many 'post to post' relationships, but I need the 'Connect to/from' box to have a different title for each relationship.
Like this -
(post to post relationship #1) Events to Venues => from 'Connected to' to 'Linked Venues'
(post to post relationship #2) Venues to Work Zones => from 'Connected to' to 'Assigned Work Zones'May 11, 2021 at 10:22 PM #28105Long Nguyen
ModeratorHi,
You can create many relationships between objects as you want: post types, users, terms.
Forpost
object, specific bypost_type
setting.
Forterm
object, specific bytaxonomy
setting.add_action( 'mb_relationships_init', function() { MB_Relationships_API::register( [ 'id' => 'events_to_venues', 'from' => [ 'object_type' => 'post', 'post_type' => 'event', 'meta_box' => [ 'title' => 'Link to Venues' ] ], 'to' => [ 'object_type' => 'post', 'post_type' => 'venue', 'meta_box' => [ 'title' => 'Assigned Events' ] ], ] ); } );
add_action( 'mb_relationships_init', function() { MB_Relationships_API::register( [ 'id' => 'venues_to_workzone', 'from' => [ 'object_type' => 'post', 'post_type' => 'venue', 'meta_box' => [ 'title' => 'Link to Work Zones' ] ], 'to' => [ 'object_type' => 'post', 'post_type' => 'workzone', 'meta_box' => [ 'title' => 'Link to Venues' ] ], ] ); } );
add_action( 'mb_relationships_init', function () { MB_Relationships_API::register( [ 'id' => 'categories_to_workzone', 'from' => [ 'object_type' => 'term', 'taxonomy' => 'category', 'meta_box' => [ 'title' => 'Assigned Work Zones' ] ], 'to' => [ 'object_type' => 'post', 'post_type' => 'workzone', 'meta_box' => [ 'title' => 'Link to Categories' ] ], ] ); } );
Please read more on the documentation
https://docs.metabox.io/extensions/mb-relationships/#terms-to-posts
https://docs.metabox.io/extensions/mb-relationships/#users-to-postsMay 11, 2021 at 11:35 PM #28109@mindspark
Participantthanks! that's easy - and thanks for building in those parameters!
-
AuthorPosts
- You must be logged in to reply to this topic.