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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #35885
    030tango030tango
    Participant

    I 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?

    #35896
    Long NguyenLong Nguyen
    Moderator

    Hi,

    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/7e9505be0b3fc2ac69a1fc1ffba714cb4ede41f8

    You 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-code

    Let me know how it goes.

    #35908
    030tango030tango
    Participant

    Not 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.

    #35925
    030tango030tango
    Participant

    So 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',
    
    		],
    
    		],
    		
        ] );
    } );
    
    #35950
    Long NguyenLong Nguyen
    Moderator

    Hi,

    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.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.