[PHP - WordPress] Ottenere l’ID della pagina da uno slug

In questo semplice tutorial WordPress vi mostreremo come creare una funzione che restituisce l'ID della pagina passando come parametro uno slug.

 
function get_page_id($name)
{
	global $wpdb;
	// get page id using custom query
	$page_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE ( post_name = '".$name."' or post_title = '".$name."' ) and post_status = 'publish' and 
									post_type='page' ");
	return $page_id;
}
 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>