i want to have different homepage according the user role login
if the user is not log they have a landing page with login
if a candidate is log the home page is custom for candidate
if a employer is log the home page is custom for employer
i have create my home page directly in wordpress not in code with page.php
and I want to have the same url for 3 home page
so I write in other question here : Dynamic homepage according to user role
I try that :
function wpse_273872_pre_get_posts( $query ) { if ( $query->is_home() && $query->is_main_query() ) { if(!is_user_logged_in()) return; $current_user = wp_get_current_user(); $user = new WP_User( $current_user->ID); if(in_array('candidate', $user->roles)){ //assuming the role name is candidate $query->set('p', [ID of the page you created for candidate]); $query->set('post_type', 'page'); } elseif(in_array('company', $user->roles)){ //assuming the role name is company $query->set('p', [ID of the page you created for employer]); $query->set('post_type', 'page'); } } } add_action( 'pre_get_posts', 'wpse_273872_pre_get_posts' ); but he doesn't work I dont now why
any solution ?
thanks