adsense

How to Find a WordPress Post ID





Find the ID in the Dashboard
1. Log into the WordPress dashboard by visiting this page:http://yourdomain.com/wp-adminType in your user name and password, if prompted, and then press 'Enter' to log in. The dashboard is the control panel for your WordPress website.
2. Click 'Posts' in the left-hand menu and then click the post you want to check. Look at the address bar of your browser. The address contains a URL for 'post.php' plus a question mark and 'post=' with a number following that. The number is the ID for that post. While you can change the post title or the 'slug,' the ID always remains the same.

3. Click 'Pages' in the left-hand menu and then click the title of a page. Look at the address bar again. Like with posts, pages also get post ID numbers. In the case of IDs, WordPress treats pages and posts the same way.
Find the ID Programmatically
4. Navigate to the folder of your current WordPress theme and open any template files you wish to edit using a code editor like Notepad , jEdit or BBEdit. You can also edit from the dashboard by navigating to 'Appearance' and then 'Editor.' Files are listed on the far-right side.
5. Use the get_the_ID() function to find the ID of a post or page. This function returns the ID without displaying it on a Web page; use the_ID() to display the post ID as content on the post or page. Assign the ID to a variable so you can pass it to other functions. Here is an example:$post_id = get_the_ID();
6. Get the post ID by its title using a MySQL query. This is more complicated because WordPress does not offer a template tag function to do all the technical work for you. Here is some sample code:
get_var('SELECT ID FROM $wpdb->posts WHERE post_title = '' . $title . ''');?>The above code sets a variable to 'Sample Post' that is then passed into a MySQL query. The query itself is saved to the 'titleid' variable. You can then pass that variable somewhere else in the code or output it using '
'.

Comments

0 Responses to "How to Find a WordPress Post ID"

Post a Comment

Popular Posts

About