I have a custom post type template where am looping through all post. what i am trying is when i go to my custom post page i want to get the current post id in the loop.
So i tried to check if the permalink is same for the post inside the loop if it is same i’ll get the post id of the current post in the loop.
Here is the code i tried
First trying to get the permalink in outside to check it inside the loop
$permalink = get_permalink();
Now i got the current post permalink now i want to get the current post id
if($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
if(the_permalink()==$permalink){
echo get_the_ID();
}else{
echo "not found";
}
endwhile;
wp_reset_postdata();
endif;
I tried this things in single-{custom-post-name}.php
am getting not found
.
can anyone give me a way to get the current post id in this template?