wordpress - Better URL formatting with Custom Post Types and Taxonomies -


i'm using toolset types , wondering how easy set url's how want.

i have custom post type of venues , have custom category taxonomy of location.

currently urls coming out

http://domain.com/venue/location/manchester/ http://domain.com/venue/manchester/the-venue-name/ 

but want url's structured

http://domain.com/manchester/ http://domain.com/manchester/the-venue-name/ 

where need make these changes?

is .htaccess work or can done within permalinks section?

thanks in advance

if understand right, hack must work in template. first of have remove post type name url slug.

function ft_remove_posttype_slug_fromurl( $post_link, $post, $leavename ) {     if ( 'venue' != $post->post_type || 'publish' != $post->post_status ) {         return $post_link;     }     $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );     return $post_link; } add_filter( 'post_type_link', 'ft_remove_posttype_slug_fromurl', 10, 3 ); 

but not gonna work itself. if u pate code in functions.php u should 404 error.bbecause wordpress expects posts , pages behave way.

so, have add action also.

function ft_change_parsingrequest( $query ) {      if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {         return;     }     if ( ! empty( $query->query['name'] ) ) {         $query->set( 'post_type', array( 'post', 'venue', 'page' ) );     } } add_action( 'pre_get_posts', 'ft_change_parsingrequest' ); 

after this, renew / refresh yours post type / permalink tree (it calls flush_rewrites guess.), means, re-update permalink settings on admin panel area.

or if want see or magic, can check out source url.

https://core.trac.wordpress.org/browser/tags/4.3/src/wp-includes/post.php#l1454

this line says;

add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%", $permastruct_args ); 

happy coding.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -