I’m trying to build a possibly simple setup for defining named, directional relationships between objects. Say, if A is “north of” B, then B is “south of” A. This could be a unidirectional relationship, it’s all a matter of querying for From or To, obviously, but I need the names of the directions to be easily user-defined and listed, so that a simple query can list all relationships of A (“A is south of B, precedes C, bigger than D”) . Does this plugin cover such a case, or do I need to write some kind of wrapper?
]]>Hello,
The “uninstall.php” file triggers the command to delete the mb_relationships table, while the “loader.php” file checks whether the table was created and files its creation in options.
When reinstalling the plugin, this logic causes the table to never be created again!! Any attempt to record relationships will generate the error_log “mb_relationships’ doesn’t exist for query” and the plugin will never be usable again.
In my opinion, uninstall.php with its cleaning command should not exist, as I may be temporarily uninstalling the plugins, and if I have many archived relationships, it will be a huge inconvenience to lose them.
]]>I get the following error since updating to v. 1.11.2:
Got error 'PHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) \n\t\t\tWHERE 1=1 AND ((wp_posts.post_type = 'post' AND (wp_posts.post_status...' at line 2 for query \n\t\t\tSELECT wp_posts.* , mbr.from\n\t\t\tFROM wp_posts INNER JOIN wp_mb_relationships AS mbr ON (mbr.to = wp_posts.ID AND mbr.type = 'posts_to_pages' AND mbr.from IN ()) \n\t\t\tWHERE 1=1 AND ((wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending')))\n\t\t\tGROUP BY mbr.from, wp_posts.ID\n\t\t\tORDER BY mbr.order_from\n\t\t\t\n\t\t made by do_action('wp_ajax_nopriv_as_async_request_queue_runner'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Request->maybe_handle, ActionScheduler_AsyncRequest_QueueRunner->handle, do_action('action_scheduler_run_queue'), WP_Hook->do_action, WP_Hook-...PHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')) \n\t\t\tWHERE 1=1 AND ((wp_posts.post_type = 'post' AND (wp_posts.post_status...' at line 2 for query \n\t\t\tSELECT wp_posts.* , mbr.from\n\t\t\tFROM wp_posts INNER JOIN wp_mb_relationships AS mbr ON (mbr.to = wp_posts.ID AND mbr.type = 'posts_to_pages' AND mbr.from IN ()) \n\t\t\tWHERE 1=1 AND ((wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending')))\n\t\t\tGROUP BY mbr.from, wp_posts.ID\n\t\t\tORDER BY mbr.order_from\n\t\t\t\n\t\t made by do_action('wp_ajax_nopriv_as_async_request_queue_runner'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Request->maybe_handle, ActionScheduler_AsyncRequest_QueueRunner->handle, do_action('action_scheduler_run_queue'), WP_Hook->do_action, WP_Hook-...'
My code for enabling relationships is:
add_action("mb_relationships_init", function () {
MB_Relationships_API::register([
"id" => "posts_to_pages",
"from" => "post",
"to" => "post",
]);
});
]]>
Hi,
I am trying to create a custom query (with the tuto of?brickslabs)
I have a custom post : member ; order and training linked like this :
CPT member <–> CPT Order <–> CPT Training
I have a MB relationship ‘member-order’ and ‘order-training’
I would like to list all the training that are followed by the member display (get_the_ID())?
I read the documentation of Metabox Relationship : https://docs.metabox.io/extensions/mb-relationships/#query-by-multiple-relationships
But couldn’t make it work. And I don’t know how I can specify that I want to display the trainings post-type.
So in each single page of a member, I can display all his trainings (in a second time, I would like to filter according to custom fields in the order’s post (like “paid” or “followed and success”)
Have you an idea ? Thank you so much !
]]>Hi,
Great plug-in. I have no issues creating simple relationships but I am trying to create the following type of relationship and would appreciate a bit of direction on how to do it or if it is possible:
Relationship is: post to portfolio
Where to show relationship results: post
What to show: posts related to portfolio entries that are related to the specific post where the results are to be shown (single template).
Thanks in advance.
Chris
Hi, I have Meta Box (free version) installed, and have used it to create custom post types and taxonomies. I am trying to use MB Relationship to link the post types that were created using Meta Box. However, the option of Relationship in the menu is not appearing; all I see is Dashboard, Post Type, and Taxonomy. Can MB Relationship not be used with Meta Box – Free version? BTW, I am on WordPress 5.9. Please clarify.
]]>Hello!
I have created a relationship of “user” to “something”(custom post type) with ID users_to_something.
Then I try to query the relationship between them.
<?php
global $post;
$args = array(
'post_type' => 'something',
'posts_per_page' => -1,
);
MB_Relationships_API::each_connected(
array(
'id' => 'users_to_something',
'from' => $test_query->posts, // tried both to/from
'property' => 'clients',
)
);
$test_query = new WP_Query( $args );
while ( $test_query->have_posts() ) :
setup_postdata( $post );
$test_query->the_post();
var_dump($post); // the relationship parameter "clients" has nothing inside
// Display connected pages (not working because there is no relationships found by each_connected)
foreach ( $post->clients as $p ) :
// More core here...
endforeach;
// Get individually(Working properly.).
$users = get_users(
array(
'relationship' => array(
'id' => 'users_to_something',
'to' => get_the_ID(),
),
)
);
foreach ( $users as $user ) {
echo $user->display_name;
}
endwhile;
The “each_connected” function seems not working as expected but query separately using “get_user” seems to working.
In this code, is there anything missed in the “each_connected”?
I have a 6000 of custom post type objects. I would like to create a page for each relation ship and register in xml to google can index it. Any idea how this plugin could help me? =)
]]>The plugin is wonderful and we look for further use cases!
So far our routine with the plugin is:
1. Manually insert regular WordPrres links to other posts on our blog in the post body; and then
2. Manually insert the linked posts into the MB Relationships meta box in order to relate them bidirectionally to the current post.
Is there a way to achieve these steps altogether, i.e. the MB Relationship to be created automatically upon link creation?
Thank you very much!
]]>Hi,
We use this plugin, it works great, but we need to disable of the directions(“To” in the code) because there relationships on this direction are huge and we don’t need them. With every update I need to comment this line, so our site works:
// if ( ! $this->to[‘meta_box’][‘hidden’] ) {
// $meta_boxes[] = $this->parse_meta_box( ‘to’ );
// }
in meta-boxes.php line 70.
Please we need this option urgent, which can be preserved over updates.
]]>Good day,
The plugin sounds promising but does not seem to work in my WP 5.5.1.
Could you help out?
Thanks.
Kind regards,
Joko
I’ve added a snippet to connect users to my custom post type “program”. The meta box can be seen on programs and connections made/saved, but there is no meta box on user profile pages. What am I missing?
add_action( 'mb_relationships_init', function() {
MB_Relationships_API::register( array(
'id' => 'users_to_programs',
'from' => array(
'object_type' => 'user',
'meta_box' => array(
'title' => 'Program',
'context' => 'normal',
),
),
'to' => array(
'object_type' => 'post',
'post_type' => 'program',
'meta_box' => array(
'title' => 'Program Followers',
'context' => 'side',
'empty_message' => 'No users',
),
),
) );
} );
]]>
Hi MetaBox Support,
I’m trying to rebuild the functionality on my website that was created using the Posts 2 Posts plugin connecting a custom post type ‘Contributors’ to my posts.
I’m already creating the ‘Contributors’ custom post type in my function.php file, & this is the code that I’d like to replace using your plugin:
add_action('p2p_init', function(){
p2p_register_connection_type(array(
'name' => 'contributor',
'cardinality' => 'many-to-many',
'from' => 'contributor',
'sortable' => 'any',
'to' => array('post','page'),
'title' => array(
'from' => 'Connected Posts and Pages',
'to' => 'Connected Contributors'),
'admin_box' => array(
'show' => 'any',
'context' => 'advanced')
));
});
I’ve read through the documentation but cannot figure out how to convert this function using your plugin. Many thanks.
]]>Hello and congrats for the excellent plugin!
We use the post-to-post functionality and it seems to work very well.
Is there a way to display additional information about the connected posts using the shortcode, e.g. connected post excerpt and author?
So far we get list of post titles, including links.
Thank you.
]]>How to restrict to one-to-one relationship from users to terms? Thanks!
]]>Hi,
I have installed the plug in, it shows me the 2 boxes Connect To and Connect From. Connect To works fine, but when I go to connected post, in Connect From box, there is nothing. Once I make update on this last post, the relationship is removed(from DB). I will fix it on my side, but this is surely a bug and needs to be fixed.
To reprouce:
1. Create relationship post to post
2. Go to post 1.
3. Create a connection to post 2 from Connect To.
4. Go to post 2.
5. ERR: Nothing displayed in Connect From.
6. Update post 2(any update).
7. Go to post 1.
8. ERR: Connection removed from Connect To.
In my case I have post to post relationships.
Cheers,
Stefan.
Is there possibility programmatically delete all connections for post? I know I can delete some certain connections (from_id and to_id) but if I want just delete all? I think I could just query all connections and save ids and then delete each by each but I feel this would make it slower.
]]>I have a custom post type work
and I would like each work to have a list of related works. If the page for work A includes a link to work B, then the page for work B should also include a link to work A.
I have tried setting up such a relationship as follows:
MB_Relationships_API::register( array(
'id' => 'works_to_works',
'from' => array(
'object_type' => 'post',
'post_type' => 'work',
'meta_box' => array(
'title' => 'Related From',
'context' => 'advanced',
'empty_message' => 'Not related from another work',
),
),
'to' => array(
'object_type' => 'post',
'post_type' => 'work',
'meta_box' => array(
'title' => 'Related To',
'context' => 'advanced',
'empty_message' => 'Not related to another work',
),
),
) );
However this creates 2 metaboxes on the work entry page, in other words I have to manually create the reverse of a given relationship. Consider the following scenario:
When registering a relationship, it would be really nice if there was a ‘bidirectional’ parameter which, when set to true (and when both ends of the relationship are of the same type?), would mean that only one metabox is displayed for an object A and any related object B added using this metabox would automatically show a link to object A.
I have tried several hacks to try and achieve this behaviour but have not managed to get any of them to work (I’m a WordPress newbie and have not yet quite got my head around the data model / code structure).
If I make the from metabox hidden and use the following 2 queries in the single_work_php
script…
‘relationship’ => array(
‘id’ => ‘works_to_works’,
‘from’ => get_the_ID(),
)`
…and…
‘relationship’ => array(
‘id’ => ‘works_to_works’,
‘to’ => get_the_ID(),
)`
…this does not address the metabox issue on the work entry page – when editing work B, I cannot edit a link to work A created on work A’s entry page.
I tried creating a trigger to automatically create reverse relationships (swapping from and to) but MySQL does not allow a trigger to insert another row in the same table that caused the trigger to fire.
I’ve also considered making the from metabox hidden and trying to add some Javascript that updates it whenever the the to box is changed. Not sure how to go about this though.
Note it would also be nice if:
Any ideas would be most welcome.
]]>Is there a way to do the 2 following things:
1) Change the label of the metabox where a relationship is selected. Currently it either says, “Connected To” or “Connected From”, but it this is not specific enough as it does not indicate which type it to or from. Is there a way to customize this label?
2) Is there a way to set the linked, related items within the list of related items to link to the page of the related item? In the Posts to Posts plugin this would happen automatically once a related item is selected. In MB Relationships, selected items are part of drop down list still so one cannot click them to go to the related editor page. Is there a way to configure it to do so?
Thanks!
]]>Hi,
in the MB Relationships ADMIN “from”-Metabox, the sort order of the related “to”-posts gets lost whenever a “to”-post is edited and saved. Sometimes the sort order gets reversed.
So whenever I have edited and saved a “to”-post and later want to edit a “from”-post, I have to manually reorder all “to”-posts in the MB Relationships Metabox before saving. This is slightly annoying in development and a no-go in production.
Can you please look into this?
Thanks
Per
Here is my MB Relationships config:
MB_Relationships_API::register( array(
‘id’ => ‘tours_to_locations’,
‘from’ => array(
‘object_type’ => ‘post’,
‘post_type’ => ‘product’,
‘meta_box’ => array( ‘context’ => ‘advanced’, ‘title’ => ‘Locations’ ),
),
‘to’ => array(
‘object_type’ => ‘post’,
‘post_type’ => ‘location’,
‘admin_column’ => ‘after title’,
‘meta_box’ => array( ‘context’ => ‘normal’, ‘title’ => ‘Used in Tours’ ),
),
) );
Hello,
Can I have custom tables with the MB-Tables extension and have separate relationship tables between those custom post types that are in (MB-Tables) separated tables?
]]>Hi,
Great plug-in. It has worked great where the site is in one language. My current challenge is understand how to get the plug-in to work with multiple languages. I am using WPML to create French versions of my English entries. As a bit of context:
-Relationships are between various custom post types.
-Relationships are all many-to-many
-Relationships shown in the post front-end using a short code. The short code includes an input to identify the specific relationship being queried, which is in English.
My guess is that the related posts do not show on the French front-end page due to
-how the entries are translated or
-how the CPT name is translated or
-the need to create a different relationship for the terms in the new language or
-some other reason
Any assistance in getting the plug-in to work with the WPML would be very much appreciated.
]]>I am wondering if this plugin would enable me to replicate the following which I was able to do in Rails.
I have a database of movies. In it, I had a many-to-many relationship between a PROJECTS table and a PROJECT_MEMBERS table with a pivot table in between, ROLES. This ROLES table contained, not only the role this project member played in the project (actor, director, etc), but also the character name if the role was actor.
Is there a way to do this with this plugin?
I installed this plugin and so far not having much luck with it.
]]>hello,
i use the last version of wp and mb-relationships.
I create a simple plugin for use and declare Relationships like this :
MB_Relationships_API::register( array(
'id' => 'projet_to_contact',
'from' => array(
'object_type' => 'post',
'post_type' => 'emf_projets',
'meta_box' => array(
'title' => 'Contact lié',
'context' => 'normal',
'field_title' => 'Select contact',
),
),
'to' => array(
'object_type' => 'post',
'post_type' => 'emf_contact',
'meta_box' => array(
'title' => 'Projets lié',
'context' => 'side',
'field_title' => 'Select Projet',
),
),
) );
when i use the native WP function wp_delete_post(); i have 15 Warning :
Warning: Illegal string offset ‘object_type’ in /home/emf/public_html/dev.emf.fr/wp-content/plugins/mb-relationships/inc/class-mb-relationships-relationship.php on line 148
And the post is not deleted…
Can you help me ?
]]>Hello,
I am discovering this plugin and I am advancing really fast with its implementation, but I am having some troubles for creating a list of people in a personal project.
In this project, I am playing with three different custom post types, that is: people, events and books. I created three principal relationships between them : author (relationship between people and book), organiser (a first relationship between people and event) and participant (a second relationship between people and event). That means that my relationships are also defining some people’s roles.
I need help to create a list of people in which I can separate them by roles. In this way :
– A List of authors : people connected with books.
– A List of organisers: people connected with events (1).
– A List of participants: people connected with events (2).
The list will be printed in a specific template called ??list-of-people.php??. By the moment, I have managed to create a list of people, but I have been unable to separate them according to the roles or relationships that I created in a specific plugin related to MB Relationships. I managed to print and separate the relationships created when I am working on a single event template or on a single person template. In this case, I cannot figure out what kind of query can I use on my “list-of-people.php” template to filter people following the relationships created before. Can you put me on the good way?
]]>