Aggiungi la base della categoria all'URL nel tipo di post personalizzato / tassonomia
-
-
Di recente,affronto questoproblema.** Risolto! ** [# 188834] [1] [1]: http://wordpress.stackexchange.com/questions/94817/add-category-base-to-url-in-custom-post-type-taxonomy/188834#188834Recently, I face this issue. **Solved!** [#188834][1] [1]: http://wordpress.stackexchange.com/questions/94817/add-category-base-to-url-in-custom-post-type-taxonomy/188834#188834
- 0
- 2015-05-20
- maheshwaghmare
-
** SOLUZIONE! ** (Dopoinfinite ricerche)
dovrestimodificareilfiltro `post_type_link`.più su: http://wordpress.stackexchange.com/a/167992/33667)**SOLUTION!** (After endless research)
you should modify the `post_type_link` filter. more at: http://wordpress.stackexchange.com/a/167992/33667 )- 0
- 2015-07-26
- T.Todua
-
possibile duplicato di [Comemodificare la struttura delpermalinkperiltipo dipostpersonalizzatoe le suetassonomie?] (http://wordpress.stackexchange.com/questions/28979/how-to-change-permalink-structure-for-custom-post-type-e-sue-tassonomie)possible duplicate of [How to change permalink structure for custom post type and it's taxonomies?](http://wordpress.stackexchange.com/questions/28979/how-to-change-permalink-structure-for-custom-post-type-and-its-taxonomies)
- 0
- 2015-07-26
- T.Todua
-
9 risposta
- voti
-
- 2013-04-06
Modifica la riscritturaper aggiungere la query del corso var:
'rewrite' => array('slug' => 'courses/%course%')
Quindifiltra
post_type_link
perinserireil corso selezionatonelpermalink:function wpa_course_post_link( $post_link, $id = 0 ){ $post = get_post($id); if ( is_object( $post ) ){ $terms = wp_get_object_terms( $post->ID, 'course' ); if( $terms ){ return str_replace( '%course%' , $terms[0]->slug , $post_link ); } } return $post_link; } add_filter( 'post_type_link', 'wpa_course_post_link', 1, 3 );
Ci sono ancheplug-in come permalink ditipopostpersonalizzato chepossonofarloperte.
Change your rewrite to add the course query var:
'rewrite' => array('slug' => 'courses/%course%')
Then filter
post_type_link
to insert the selected course into the permalink:function wpa_course_post_link( $post_link, $id = 0 ){ $post = get_post($id); if ( is_object( $post ) ){ $terms = wp_get_object_terms( $post->ID, 'course' ); if( $terms ){ return str_replace( '%course%' , $terms[0]->slug , $post_link ); } } return $post_link; } add_filter( 'post_type_link', 'wpa_course_post_link', 1, 3 );
There are also plugins like Custom Post Type Permalinks that can do this for you.
-
Grazie,apprezzo latua rapida risposta.Questo haperfettamente senso.Sono curiosoperò,doveinseriscoilfiltropost_type_link?posso semplicemente andarein fondo all'intero documento?Thank you, I appreciate your swift answer. This makes complete sense. I'm curious though, where do I insert the filter post_type_link at? can i just go at the bottom of the entire document?
- 0
- 2013-04-06
- Zach Russell
-
L'ho aggiuntoin fondoe 404 è lapagina.I added it to the bottom and it 404's the page.
- 0
- 2013-04-06
- Zach Russell
-
devi svuotare le riscritture,visita lapagina delleimpostazioni deipermalink.you have to flush rewrites, visit the permalinks settings page.
- 1
- 2013-04-06
- Milo
-
nota anche cheprobabilmente avrai uno scontro con unatassonomiae untipo dipost che condividonoentrambi lo stesso slug.also note you'll likely have a clash with a taxonomy and a post type both sharing the same slug.
- 0
- 2013-04-06
- Milo
-
Dovemi trovo ora stafacendoi permalinkgiusti,manon si staeseguendo correttamente (è un 404 soft).Qualche consiglio su cosapossofareperfarlofunzionarebene?Sono lontano dalle riscritture afilo delpermalink.Bastafare clic su "salva"e aggiornailfile (ènginx quindi è controllatonelfilenginx.conf)Where i'm at now is it's making the permalinks right, but it's not executing correctly (it's soft 404ing). Any recommendations on what I can do to get this working right? I'm away of the permalink flush rewrites. Just click 'save' and it updates the file (it's nginx so it's controlled in the nginx.conf file)
- 0
- 2013-04-06
- Zach Russell
-
Fatto!È stato un conflitto.Got it! It was a conflict.
- 0
- 2013-04-06
- Zach Russell
-
Downvote -pagina di archivio 404Downvote - archive page 404
- 1
- 2020-04-04
- Dev
-
Questononfunzionaperi posttradotti su un sitomultilingue (adesempio utilizzando WPML).This doesn't work for translated posts on a multilingual site (for example using WPML).
- 0
- 2020-08-05
- montrealist
-
Questomostra laprimapaginaperme sull'URL appena creato.Devi usare add_rewrite_rule () vistonella risposta di @ Florisperfarlofunzionare.Notainoltre,lepagine di archivio smettono difunzionare,ottengo 404per/my-post-typee per/my-post-type/my-categoryThis shows frontpage for me on the newly created URL. You gotta use the add_rewrite_rule() seen in @Floris's answer to make it work. Also note, archive pages stop working, I get 404 for /my-post-type and for /my-post-type/my-category
- 0
- 2020-09-01
- trainoasis
-
- 2019-02-11
La soluzioneperme avevatreparti. Nelmio casoiltipo dipost si chiama
trainings
.- Aggiungi
'rewrite' => array('slug' => 'trainings/%cat%')
allafunzioneregister_post_type
. - Cambia lo slugper avere una categoria dinamica.
- "Ascolta"ilnuovo URL dinamicoe caricailmodello appropriato.
Ecco quindi comemodificare dinamicamenteilpermalinkper un datotipo dipost. Aggiungi a
functions.php
:function vx_soon_training_post_link( $post_link, $id = 0 ) { $post = get_post( $id ); if ( is_object( $post ) ) { $terms = wp_get_object_terms( $post->ID, 'training_cat' ); if ( $terms ) { return str_replace( '%cat%', $terms[0]->slug, $post_link ); } } return $post_link; } add_filter( 'post_type_link', 'vx_soon_training_post_link', 1, 3 );
...edecco come caricareilmodello appropriato sulnuovo URL dinamico. Aggiungi a
functions.php
:function archive_rewrite_rules() { add_rewrite_rule( '^training/(.*)/(.*)/?$', 'index.php?post_type=trainings&name=$matches[2]', 'top' ); //flush_rewrite_rules(); // use only once } add_action( 'init', 'archive_rewrite_rules' );
Questo ètutto! Ricorda di aggiornarei permalink salvando dinuovoi permalinknelbackend. Oppure usa lafunzione
flush_rewrite_rules()
.The solution for me had three parts. In my case the post type is called
trainings
.- Add
'rewrite' => array('slug' => 'trainings/%cat%')
to theregister_post_type
function. - Change the slug to have a dynamic category.
- "Listen" to the new dynamic URL and load the appropriate template.
So here is how to change the permalink dynamically for a given post type. Add to
functions.php
:function vx_soon_training_post_link( $post_link, $id = 0 ) { $post = get_post( $id ); if ( is_object( $post ) ) { $terms = wp_get_object_terms( $post->ID, 'training_cat' ); if ( $terms ) { return str_replace( '%cat%', $terms[0]->slug, $post_link ); } } return $post_link; } add_filter( 'post_type_link', 'vx_soon_training_post_link', 1, 3 );
...and this is how to load the appropriate template on the new dynamic URL. Add to
functions.php
:function archive_rewrite_rules() { add_rewrite_rule( '^training/(.*)/(.*)/?$', 'index.php?post_type=trainings&name=$matches[2]', 'top' ); //flush_rewrite_rules(); // use only once } add_action( 'init', 'archive_rewrite_rules' );
Thats it! Remember to refresh the permalinks by saving the permalinks again in de backend. Or use the
flush_rewrite_rules()
function. -
- 2017-10-06
Hai la soluzione!
Per averepermalinkgerarchiciperiltipo dipostpersonalizzato,installai permalink ditipopostpersonalizzato ( https://wordpress.org/plugins/custom-post-type-permalinks/).
Aggiornailtipo dipost registrato. Hoilnome deltipo dipost come Centro assistenza
function help_centre_post_type(){ register_post_type('helpcentre', array( 'labels' => array( 'name' => __('Help Center'), 'singular_name' => __('Help Center'), 'all_items' => __('View Posts'), 'add_new' => __('New Post'), 'add_new_item' => __('New Help Center'), 'edit_item' => __('Edit Help Center'), 'view_item' => __('View Help Center'), 'search_items' => __('Search Help Center'), 'no_found' => __('No Help Center Post Found'), 'not_found_in_trash' => __('No Help Center Post in Trash') ), 'public' => true, 'publicly_queryable'=> true, 'show_ui' => true, 'query_var' => true, 'show_in_nav_menus' => false, 'capability_type' => 'page', 'hierarchical' => true, 'rewrite'=> [ 'slug' => 'help-center', "with_front" => false ], "cptp_permalink_structure" => "/%help_centre_category%/%post_id%-%postname%/", 'menu_position' => 21, 'supports' => array('title','editor', 'thumbnail'), 'has_archive' => true )); flush_rewrite_rules(); } add_action('init', 'help_centre_post_type');
Edecco latassonomia registrata
function themes_taxonomy() { register_taxonomy( 'help_centre_category', 'helpcentre', array( 'label' => __( 'Categories' ), 'rewrite'=> [ 'slug' => 'help-center', "with_front" => false ], "cptp_permalink_structure" => "/%help_centre_category%/", 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'query_var' => true ) ); } add_action( 'init', 'themes_taxonomy');
Questa è la linea chefafunzionareiltuopermalink
"cptp_permalink_structure" => "/%help_centre_category%/%post_id%-%postname%/",
puoi rimuovere
%post_id%
e puoimantenere/%help_centre_category%/%postname%/"
Non dimenticare di svuotarei permalink dalla dashboard.
Got the solution!
To have hierarchical permalinks for custom post type install Custom Post Type Permalinks(https://wordpress.org/plugins/custom-post-type-permalinks/) plugin.
Update registered post type. I have post type name as help center
function help_centre_post_type(){ register_post_type('helpcentre', array( 'labels' => array( 'name' => __('Help Center'), 'singular_name' => __('Help Center'), 'all_items' => __('View Posts'), 'add_new' => __('New Post'), 'add_new_item' => __('New Help Center'), 'edit_item' => __('Edit Help Center'), 'view_item' => __('View Help Center'), 'search_items' => __('Search Help Center'), 'no_found' => __('No Help Center Post Found'), 'not_found_in_trash' => __('No Help Center Post in Trash') ), 'public' => true, 'publicly_queryable'=> true, 'show_ui' => true, 'query_var' => true, 'show_in_nav_menus' => false, 'capability_type' => 'page', 'hierarchical' => true, 'rewrite'=> [ 'slug' => 'help-center', "with_front" => false ], "cptp_permalink_structure" => "/%help_centre_category%/%post_id%-%postname%/", 'menu_position' => 21, 'supports' => array('title','editor', 'thumbnail'), 'has_archive' => true )); flush_rewrite_rules(); } add_action('init', 'help_centre_post_type');
And here is registered taxonomy
function themes_taxonomy() { register_taxonomy( 'help_centre_category', 'helpcentre', array( 'label' => __( 'Categories' ), 'rewrite'=> [ 'slug' => 'help-center', "with_front" => false ], "cptp_permalink_structure" => "/%help_centre_category%/", 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'query_var' => true ) ); } add_action( 'init', 'themes_taxonomy');
This is line makes your permalink work
"cptp_permalink_structure" => "/%help_centre_category%/%post_id%-%postname%/",
you can remove
%post_id%
and can keep/%help_centre_category%/%postname%/"
Don't forget to flush permalinks from dashboard.
-
- 2015-05-20
Sì! Dopomolte ricerche ho ottenutoilplug-in ' Permalinkpersonalizzati ".Che soddisfai miei requisitiper quanto riguarda: URLpersonalizzato,adesempio
- per categoria
- per Post
- perpostpersonalizzato
- per latassonomiapersonalizzata ecc.
Come questo Tipo dipostpersonalizzato - Post :
Yep! After a lot of research I got plugin 'Custom Permalinks'. Which fulfils my requirement regards - custom URL e.g.
- for Category
- for Post
- for Custom Post
- for Custom Taxonomy etc.
Like this Custom Post Type - Post:
-
- 2019-06-12
Devi aggiornare sotto la rigain cui hai registrato untipo dipostpersonalizzato utilizzando lafunzione register_post_type.
'rewrite'=> array ('slug'=> 'course/% cat%')
Per cambiareilpermalink dinamicamente deltipo dipost devi aggiungereil codice seguentenelfilefunctions.php:
function change_link( $post_link, $id = 0 ) { $post = get_post( $id ); if( $post->post_type == 'courses' ) { if ( is_object( $post ) ) { $terms = wp_get_object_terms( $post->ID, array('course') ); if ( $terms ) { return str_replace( '%cat%', $terms[0]->slug, $post_link ); } } } return $post_link ; } add_filter( 'post_type_link', 'change_link', 1, 3 ); //load the template on the new generated URL otherwise you will get 404's the page function generated_rewrite_rules() { add_rewrite_rule( '^courses/(.*)/(.*)/?$', 'index.php?post_type=courses&name=$matches[2]', 'top' ); } add_action( 'init', 'generated_rewrite_rules' );
Dopodiché,devi svuotarei permalink delle riscritture,vai a wp-admin> Impostazioni>permalink .basta aggiornare l'impostazione delpermalink utilizzandoilpulsante "Salvamodifiche".
restituiràgli URL come di seguito:
- domain.com/courses/[course-name{category}"/lesson-name
Grazie!
You need to update below line at where you have register a custom post type using register_post_type function.
'rewrite' => array('slug' => 'courses/%cat%')
To change permalink dynamically of post type you have to add below code in functions.php file :
function change_link( $post_link, $id = 0 ) { $post = get_post( $id ); if( $post->post_type == 'courses' ) { if ( is_object( $post ) ) { $terms = wp_get_object_terms( $post->ID, array('course') ); if ( $terms ) { return str_replace( '%cat%', $terms[0]->slug, $post_link ); } } } return $post_link ; } add_filter( 'post_type_link', 'change_link', 1, 3 ); //load the template on the new generated URL otherwise you will get 404's the page function generated_rewrite_rules() { add_rewrite_rule( '^courses/(.*)/(.*)/?$', 'index.php?post_type=courses&name=$matches[2]', 'top' ); } add_action( 'init', 'generated_rewrite_rules' );
After that, you need to flush rewrites permalinks, goto the wp-admin > Settings > permalinks. just update permalink setting using "Save Changes" button.
it'll return urls like below :
- domain.com/courses/[course-name{category}]/lesson-name
Thank you!
-
Votonegativo: 404 suentrambii tipi dipagina di archivio CPTe CTPDown vote - 404 on both single CPT and CTP archive page types
- 0
- 2020-04-04
- Dev
-
@dev hai seguitotuttii passaggi che homenzionatonellamia risposta?hai svuotatoi permalink riscritti?Hoprovatoe funzionabene.@dev did you follow all steps which i have mentioned in my answer ? did you flush your rewrite permalinks? I have tested and it is working fine.
- 0
- 2020-04-04
- Chetan Vaghela
-
- 2017-05-03
Questo hafunzionatoperme:
'rewrite' => array( 'slug' => 'portfolio', 'with_front' => false, 'hierarchical' => true // to display category/subcategroy ),
This is worked for me :
'rewrite' => array( 'slug' => 'portfolio', 'with_front' => false, 'hierarchical' => true // to display category/subcategroy ),
-
Questononfa uso delle categorie o del loropercorso,rende sologerarchicoiltipo dipostpersonalizzato.This does not make use of the categories or their path it only makes the custom post type hierarchical.
- 5
- 2017-08-25
- Joris Kroos
-
- 2019-07-01
A chiunque siainteressato alla soluzione,senza dover armeggiare conil codice PHPgrezzo,consiglio vivamenteilplugin Permalink Manager Lite di Maciej Bis.È un salvavita.
Ha unmeccanismo visivoper rimuovere o aggiungere qualsiasipartetu voglianell'URL deltipo dipostpersonalizzatobasato su "permastructs":
(Contuttoil dolore legato alla semplice strutturazione di URL contipi dipostpersonalizzati,stavamoper rinunciare a WPe passare a un altro CMS. Ma questoplug-inin combinazione con ACFe CPTUI o Pods rende Wordpress abbastanzaprofessionale.)
/p>
To anyone interested in the solution, without having to tinker with raw PHP code, I highly recommend the plugin Permalink Manager Lite by Maciej Bis. It's a life saver.
It has a visual mechanism to remove or add whatever part you want in the custom post type's URL based on 'permastructs':
(With all the pain involved in simple URL structuring with custom post types, we were about to give up on WP and move to another CMS. But this plugin in conjunction with ACF and CPTUI or Pods makes Wordpress fairly professional.)
-
- 2020-05-29
Se stai utilizzando
get_post_type_archive_link()
,forse dovrai rimuovere/%cat%/
dall'URL utilizzandoilfiltropost_type_archive_link
.If you're using
get_post_type_archive_link()
, maybe you will need to remove/%cat%/
from the URL usingpost_type_archive_link
filter. -
- 2020-08-18
Hotrovato la risposta di @ chetan-vaghela quasiperfetta;nelmio caso d'uso volevo ancheesserein grado di vedere unelenco dituttii post di questotipo dipost come unatipicapagina di archivio (cioè/corsi/,senza alcunatassonomia dopo).Dovevo solo aggiungere un'ulteriore regola di riscrittura come segue:
function generated_rewrite_rules() { add_rewrite_rule( '^courses/(.*)/(.*)/?$', 'index.php?post_type=courses&name=$matches[2]', 'top' ); }
I found @chetan-vaghela 's answer almost perfect; in my use case I also wanted to be able to see a list of all posts by this post type like a typical archive page (i.e. /courses/, without any taxonomy after it). I just had to add one additional rewrite rule as follows:
function generated_rewrite_rules() { add_rewrite_rule( '^courses/(.*)/(.*)/?$', 'index.php?post_type=courses&name=$matches[2]', 'top' ); }
Sto costruendo un sistema ditipi LMSin WordPress,controllato da
Tipi dipostpersonalizzati
.Iltipo di articolo si chiama
Lessons
(con uno slug dicorsi
)e ha unatassonomiapersonalizzata
(categoria) chiamatacorsi .
La struttura dell'URL del dominio almomento appare come:
domain.com/courses/lesson-name
.Voglio che diventi:
domain.com/courses/[course-name{category}"/lesson-name
oessenzialmente:
/[cpt]/% category%/%postname%/
eccoilplugin che ho scritto che controllai
CPT
ora.