Query Args don't work the same for Relationships and Post fields
Support › MB Relationships › Query Args don't work the same for Relationships and Post fields
- This topic has 4 replies, 2 voices, and was last updated 3 years ago by
Long Nguyen.
-
AuthorPosts
-
May 5, 2022 at 5:27 AM #35885
030tango
ParticipantI got a page, where I use relationship fields to connect video posts to "The Events Calendar" events, organizers and so forth.
The problem I have is, that when I want to connect a "video" to a past "event", I can define the relationship just in the "event" post, not the "video", as past events get filtered out.
When I add a regular custom field of the "post" type, I can use the query args:
suppress_filters => true
and past events show up in the video post.When i use the same query arg in a relationship, it's not working.
Maybe someone has an idea why that is?
May 5, 2022 at 12:23 PM #35896Long Nguyen
ModeratorHi,
There is an issue with the setting
query_args
of the relationship, it is fixed in this commit https://github.com/wpmetabox/mb-relationships/commit/7e9505be0b3fc2ac69a1fc1ffba714cb4ede41f8You can download this branch to your site and follow the documentation to use the query_args with coding
https://docs.metabox.io/extensions/mb-relationships/#using-codeLet me know how it goes.
May 6, 2022 at 6:06 AM #35908030tango
ParticipantNot so great. You will be shocked to read, that one of the reasons I chose Metabox are the easy relationships and the no code approach...
Guess I have to hire a developer for bugfixing this on my page.
May 7, 2022 at 2:13 AM #35925030tango
ParticipantSo I managed to add the relationship via code and also implemented the changes from the commit.
I can now see all events, present and past. The videos show up in the events, where they are supposed to.
But as soon as I hit "save" on a video, the relationships field jumps back to "select an event"This is the code for the relationship I used:
add_action( 'mb_relationships_init', function () { MB_Relationships_API::register( [ 'id' => 'video_to_events', 'from' => [ 'object_type' => 'post', 'post_type' => 'video', 'meta_box' => [ 'title' => 'Event related to Video Neu', ], 'field' => [ 'label' => 'Event related to Video Neu', ], 'query_args' => [ 'post_status' => 'any', 'suppress_filters' => 'true', ], ], 'to' => [ 'object_type' => 'post', 'post_type' => 'tribe_events', 'meta_box' => [ 'title' => 'Videos related to Event Neu', ], 'field' => [ 'label' => 'Videos related to Event Neu', ], 'query_args' => [ 'post_status' => 'any', 'suppress_filters' => 'true', ], ], ] ); } );
May 8, 2022 at 6:05 PM #35950Long Nguyen
ModeratorHi,
You can try to follow this tutorial to increase the PHP setting
max_input_vars
to fix the issue
https://metabox.io/wordpress-custom-fields-not-saving-increase-max-input-vars/Let me know how it goes.
-
AuthorPosts
- You must be logged in to reply to this topic.