How can I get the post slug from a post ID?
So if I change the slug - WP still knew what slug has the post (with the ID).
How can I get the post slug from a post ID?
So if I change the slug - WP still knew what slug has the post (with the ID).
Can you define the global $post array and use that?
I have several posts which I show the title of. So I need to use ID of the post each time. Could you give me the code of the topic question pls?
What do you want to accomplish with the slug? Echo it for each post?
Yes:
I have the post with ID 111 and the post with ID 222. So I need the code which gives me the slug of the post with ID 111 (by ID) and the same with 222.
Could you do something like
global $post;
if ( $post->ID == 111 && $post->ID == 222 ) {
echo $post->post_slug;
// I don't actually know the slug name
}This is a part of my code (there are several such pieces of different posts):
<?php
$post_id_title = get_the_title(1);
if (is_single($post_id_title)) { ?>
<li><a href="<?php bloginfo('url'); ?>/#slug" class="selected"><span><?php the_title(); ?></span></a></li>
<?php } else { ?>
<li><a href="<?php bloginfo('url'); ?>/#slug"><span><?php echo get_the_title(1); ?></span></a></li>
<?php } ?>
Here is "#slug" - I do need to get the slug by ID. The code Andrew Nevins gives me above is difficult to add to this for me...
<?php echo $post->post_slug(1); ?>
does not work...
[No bumping, thank you.]
You must log in to post.