Come ottengo il permalink di un custom post type?
Posso ottenere il permalink di uno specifico tag o categoria di un post, ma come posso ottenere il permalink di un custom post type? Non riesco a trovare nulla nel Codex o in altre parti su come fare questo.

Che ne dici di href="<?php echo get_post_type_archive_link( $post_type ); ?>"
, dove $post_type
è il tuo tipo di post?
Per approfondire: Codex

All'interno del loop, puoi semplicemente utilizzare the_permalink()
. Al di fuori del loop, puoi usare get_permalink( $id )
.

Questo restituisce il permalink di un post o pagina specifico. Voglio restituire il permalink di un tipo di post. Quindi, ad esempio, se c'è un tipo di post chiamato "recensioni di film", e il permalink di quel tipo di post è "www.website.com/recensioni-film", come faccio ad ottenere quel permalink? Forse tecnicamente non è un vero permalink, voglio semplicemente l'URL di quel tipo di post.

Oppure, per quel che vale, get_term_link($term, $taxonomy);
- Codex.

So che questo post potrebbe essere vecchio, ma nel caso qualcuno stia cercando la funzione che fa questo, ecco quella che ho scritto. $post_type deve essere passato come variabile :)
if( !function_exists( 'wp_get_post_type_link' ) ){
function wp_get_post_type_link( &$post_type ){
global $wp_rewrite;
// Verifica se esiste l'oggetto post type
if ( ! $post_type_obj = get_post_type_object( $post_type ) )
return false;
// Se i permalink sono attivi e c'è una struttura rewrite
if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) {
$struct = $post_type_obj->rewrite['slug'] ;
// Aggiunge il front alla struttura se necessario
if ( $post_type_obj->rewrite['with_front'] )
$struct = $wp_rewrite->front . $struct;
else
$struct = $wp_rewrite->root . $struct;
// Genera il link completo
$link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );
} else {
// Link semplice senza permalink
$link = home_url( '?post_type=' . $post_type );
}
// Applica i filtri e restituisce il link
return apply_filters( 'the_permalink', $link );
}
}
Spero sia utile! :)
