Support Forum
Support › MB Relationships › Post Statuses other than Published
I'm working with Relationships that I've set up for two custom post types, (slug=offer and slug=listing), which seems to be working if both posts are Published. However when I set one to Draft, or use a custom post status, the two posts lose their connection between each other. Is it possible to customize MetaBox to allow for connections between posts that aren't Published? We are going to have our custom post type 'offer' controlled with custom post statuses, (slug=accepted, slug=rejected), and I don't want to lose previously set connections when I update. Thanks!
Hi John,
Please follow this topic to use the setting query_args
to query posts by status in the relationship box https://support.metabox.io/topic/relationships-on-post_status-other-than-published/
function your_prefix_function_name() {
MB_Relationships_API::register( [
'id' => 'post-to-page',
'from' => [
'object_type' => 'post',
'post_type' => 'post',
],
'to' => [
'object_type' => 'post',
'post_type' => 'page',
'field' => [
'query_args' => [
'post_status' => array( 'publish', 'draft' )
],
],
],
] );
}
Thanks for the help, here's what I've been working with to try and get it to work based on your post and the examples you listed for dealing with a Relationship between one custom post type, (slug='offer'), to another custom post type, (slug='listing'). I've confirmed that the Relationship ID is 'listing-to-offer-relationship' by going to Meta Box > Relationships > Listing to Offer Relationship and copying it from there.
/**
* Allow Meta Box Relationship to use post statuses besides just Published
*/
add_action( 'mb_relationships_init', function() {
MB_Relationships_API::register([
'id' => 'listing-to-offer-relationship',
'from' => [
'object_type' => 'post',
'post_type' => 'listing',
'field' => [
'query_args' => [
'post_status' => array( 'publish', 'draft' )
],
],
],
'to' => [
'object_type' => 'post',
'post_type' => 'offer',
'field' => [
'query_args' => [
'post_status' => array( 'publish', 'draft', 'accepted', 'rejected' )
],
],
],
]);
});
Nothing I test has been working for me though. When I have an custom post type 'offer' in draft I can see the connected custom post type 'listing' just fine. But when I view the connected 'listing' the connected 'offer' is blank. I've tried to set the 'post_type' in both the from and to arrays to 'post' instead of 'offer' and 'listing' which didn't seem to help. I've also tried to wrap it with your example 'function your_prefix_function_name() {' instead of 'add_action( 'mb_relationships_init', function() {' and that didn't work for me either.
I've also tried to add post statuses through the Meta Box interface under Meta Box > Relationships > Listing to Offer Relationship > From > Field > Query args:
key=post_status value=publish
key=post_status value=draft
key=post_status value='publish'
key=post_status value='draft'
key=post_status value=array('publish','draft')
Along with the other matching To > Field > Query args and that didn't work either.
Hi,
Can you please share some screenshots of the issue (full screen)? And please notice that the custom field (relationship) shows on the object from
get object type, post type, and field settings from object to
.
That means when you edit a listing
post, you will see a meta box with a list of offer
posts and some post statuses.
Can you please share some screenshots of the issue (full screen)?
Here are some screenshots of what I'm seeing when I look at the offer and listing:
offer
https://prnt.sc/Db5Vz3vrv5L3
listing
https://prnt.sc/Db5Vz3vrv5L3
And please notice that the custom field (relationship) shows on the object from get object type, post type, and field settings from object to. That means when you edit a listing post, you will see a meta box with a list of offer posts and some post statuses.
I'm not sure I'm understanding what you mean here - when I view either an offer or listing I can see a dropdown for the other related field.
Hi John,
The offer and listing image links are the same. If it is a staging site, please share your site credentials via this contact form https://metabox.io/contact/. I will take a closer look.
It looks like I didn't copy the listing link correctly, you can see it here:
listing
I'll also send over the site credentials for you to get in and take a closer look.
When I try to submit the contact form, I get this error:
The link you followed has expired.
Can you send me an email directly, [email protected] so that I can respond back with the credentials?
Hi John,
To pass an array of values to an argument in the builder, please use the Dot or JSON notation, screenshot https://monosnap.com/file/Y52APzCST2t15IZsC7SutZgJrtwRII
Read more on the documentation https://docs.metabox.io/extensions/meta-box-builder/#dot-notation
Now you can see the relationship works on your site.