0

I created a custom page template that will show sales from a hotel. I have 3 users and I want each user to only see their hotel sales on a user profile specific page. The template calls data using the REST API response (custom post type). I have tried this:

<?php function get_current_user_id() {
if ( ! function_exists( 'wp_get_current_user' ) ) {
    return 0;
}
$user = wp_get_current_user();
return ( isset( $user->ID ) ? (int) $user->ID : 0 );

<?php
if ($user-> ID == 5){
    get_post(13);
}
else ( get_post(3));
?>

My idea is if it's user 5, show the page, if not show another page...

  • 1
    It's not clear whether your issue may be due to formatting, or whether the formatting errors happened when you pasted your code. Here you have a space between $user-> and ID which could cause errors. Could you please edit your question to more clearly show the code and let us know what your specific question or error is? – WebElaine May 10 at 21:41
  • Well, the code might be wrong, I am not too proficient in PHP, what I need is that the page template I created could be viewed only by a specific user, in this case the template shows rooms rented from a specific hotel, so I will use a plugin to create user roles, and each user can only see their hotel rooms rented, I have all the hotel pages done, using VueJs calling the Wordpress REST API from another WordPress website. I hope you understand .... thank you! – David Delatorre May 10 at 22:17
  • Your else syntax is wrong. You should write else get_post(3);. Also as pointed above, you have a white space before ID. Remove it. – filipecsweb May 11 at 3:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.