title: Getting Post Permalink By Post Id Doesn't Work
body: <p>In my Wordpress blog I am trying to get post permalink of a post of custom post type for which I add this code to function.php</p>
  
  <pre><code>function get_randomp() { ?&gt;
  &lt;?php 
  $args=array('post_type'=&gt;'photo', 'orderby'=&gt;'rand', 'posts_per_page'=&gt;'1'); 
  $photo=new WP_Query($args); while ($photo-&gt;have_posts()) : $photo-&gt;the_post();
  ?&gt;
  &lt;?php echo get_the_ID(); ?&gt;
  &lt;?php
  endwhile;
  wp_reset_postdata();
  ?&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>and this added this code in sidebar.php to output the permalink,</p>
  
  <pre><code>&lt;?php 
  $postidr = get_randomp();
  echo get_permalink( $postidr ); 
  ?&gt;
  </code></pre>
  
  <p>But it is showing permalink of the current post which is being viewed.
  Please help me guys.</p>