Return to Snippet

Revision: 44739
at April 17, 2011 01:18 by prwhitehead


Updated Code
/**
* 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;		
}

Revision: 44738
at April 17, 2011 01:18 by prwhitehead


Initial Code
/**
* 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;		
}

Initial URL

                                

Initial Description
Dynamically get the guid of your a post from its post title (with wordpress caching)

Initial Title
Wordpress: Get GUID from page title

Initial Tags
post, wordpress

Initial Language
PHP