/ Published in: PHP

Dynamically get the guid of your a post from its post title (with wordpress caching)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Usage: <a href="<? echo get_required_page('Sitemap'); ?>" title="Sitemap">Sitemap</a> * * */ function get_required_page($page = ''){ global $wpdb; $result = wp_cache_get($page . '-guid', __FUNCTION__); if($result === false) { $result = $wpdb->get_var("SELECT p.guid FROM $wpdb->posts p WHERE p.post_status = 'publish' AND p.post_title = '{$page}' "); if ($result) { wp_cache_add($page . '-guid', $result, __FUNCTION__); } } return $result; }
Comments
