You can use get_the_author_meta(‘ID’) to get the page/post author ID, and then use get_current_user_id() to compare it to the current user.
Thread Starter
Gustav
(@4ever16)
Yes i know those stuff i need more complete code or easier explenatioon.
We aren’t here to write code for you. 🙂
What do you have now? What does or doesn’t work?
To be honest, this ia a very simple if() statement. If you don’t know how to get that to work, you should go back and look more at some PHP basics.
if(...) {
// Show something
}
else {
// Show something else
}
Thread Starter
Gustav
(@4ever16)
Im writing from cellphone so cant post what i got but.
Get current user id and then compare it with post author id?
But can’t author id and current user id be be identical to 2 different users?
But yes i get the point now. I will try to make a code later.
I comeback when im done with it and see if i need anymore help or just post the code so anyone can use it cause i tryied google can’t find complete code for this function.
-
This reply was modified 3 years, 1 month ago by Gustav.
-
This reply was modified 3 years, 1 month ago by Gustav.
I would suggest looking at the documentation a bit more.
It also depends if your checking inside or outside the loop.
The way i would check outside the loop will be like this
if ( is_user_logged_in() && get_queried_object_id() == get_current_user_id() )
{
// Do something
}
-
This reply was modified 3 years, 1 month ago by deanjansen1.
Thread Starter
Gustav
(@4ever16)
Didn’t work inside loop atleast.
@4ever16 So can yu show us the code that you are using? If you do that we can look and see why, but if you can’t do that we have nothing to go on at all and can’t help.
Thread Starter
Gustav
(@4ever16)
I solved it like this.
<?php
if ( is_user_logged_in() && get_the_author_meta( 'ID' ) === get_current_user_id() ) {
//do something
} else {
//do something else
}
?>
OK, so do some basic debuging to see what isn’t right. Just before your if(), add in this to see what the values are:
echo "<p>Logged in: '".is_user_logged_in ()."', Author meta ID: '".get_the_author_meta ('ID')."', Current user ID: '".get_current_user_id ()."'</p>";
From there you can see what doesn’t match what it’s meant to, and you’ll know what needs more attention.
Thread Starter
Gustav
(@4ever16)
It’s solved i posted the code which solved my problem.