Getting a page ID in WordPress


Q. Want to get something in your theme to work with data from a particular page or post – but don’t know for sure what that post’s ID is?

A. Try this in your functions.php file:

$my_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = 'myPost'");

…then you can then pass a variable about in your theme’s templates.

,

  1. No comments yet.

You must be logged in to post a comment.