Last active
May 26, 2020 17:23
-
-
Save someguy9/297a21ee4d8ba1036fdf96bf9856d4df to your computer and use it in GitHub Desktop.
Get WordPress post ID by slug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$post_data = get_page_by_path('my-post-slug'); | |
$post_id = $post_data->ID; | |
if(!empty($post_id)){ | |
echo 'The post ID is: '.$post_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment