The 404 issue is because name
is a WordPress query var. Adding that in the URL causes WordPress to query for a post with slug that matches whatever is in the name
field, instead of your page. Change your form field names to something you know will be unique. This is a good practice for everything you have to name- form fields, functions, etc..
As for your menu item question, you can use the nav_menu_link_attributes
filter to alter the href
for a specific menu item. Here we check if Trainings
is the title of the menu item, and add the GET params if that is the case:
function wpd_add_logged_in_get_params(){
if( is_user_logged_in() ){
add_filter( 'nav_menu_link_attributes', function( $atts, $item ){
if( 'Trainings' == $item->title ){
$current_user = wp_get_current_user();
$atts['href'] = esc_url(
add_query_arg(
array(
'wpd_name' => $current_user->display_name,
'wpd_email' => $current_user->user_email
),
$atts['href']
)
);
}
return $atts;
}, 10, 2 );
}
}
add_action( 'template_redirect', 'wpd_add_logged_in_get_params' );