Convertire il nome del post in ID del post
Sto cercando di creare una funzione per il mio file functions.php che mi permetta di convertire il nome di un post nel suo ID. Ho cercato online e ho trovato questo link http://www.devdevote.com/cms/wordpress-hacks/get_id_by_post_name che fornisce il seguente esempio...
function get_id_by_post_name($post_name)
{
global $wpdb;
$id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$post_name."'");
return $id;
}
<?php echo get_id_by_post_name('my-post-name'); ?>
Dopo aver sostituito my-post-name nell'esempio non ottengo alcun risultato, qualcuno può suggerire cosa c'è che non va?
Stavo anche valutando la funzione get_by_postname nel caso fosse un modo migliore per ottenere questo risultato.

Utilizza get_page_by_title()
. Funziona con qualsiasi tipo di post.
$post = get_page_by_title( $post_name, OBJECT, 'post' );
echo $post->ID;

Ora sto cercando di procedere con questa funzione e convertirla in modo che utilizzi il nome del post invece dell'ID. Ho creato una nuova domanda su http://wordpress.stackexchange.com/questions/59050/combine-two-functions-highlight-menu-item-by-post-name-instead-of-id - C'è la possibilità che tu possa darci un'occhiata?
