Support MB Relationships pre_get_posts to get all posts connected to single object Reply To: pre_get_posts to get all posts connected to single object

#11663
Content PilotContent Pilot
Participant

function custom_query_vars_filter($vars) {
    $vars[] .= 'relationships';
    return $vars;
}
add_filter( 'query_vars', 'custom_query_vars_filter' );

function prefix_get_related_posts( $query ) {
    
    $post_id = get_query_var('relationships');
    
    if ( empty( $post_id ) || is_admin() ) {
        return $query;
    }

    if( is_post_type_archive( 'poa_person' ) && $query->is_main_query() ) {
        $query->set( 'relationship', 
            array( 
                'id' => 'poa_practice_to_poa_person',
                'from' => $post_id,
            )
        );
    }

    return $query;
}
add_filter( 'parse_query', 'prefix_get_related_posts', 10, 1);

parse_query works great. But now my styling is all jacked up. At least the query is working now. Thanks for the help.