$15
custom taxonomy and permalink rewrite
<?php
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy( 'event_type', 'post', array( 'hierarchical' => true, 'label' => 'Event Type', 'query_var' => true, 'rewrite' => true ) );
} ?>Currently, my url looks like this sample.com/event_type/conventions but I need to remove event_type out of the URL so it becomes sample.com/conventions
I know it's possible through wp_rewrite in functions file, but I lack enough knowledge to actually do it.Would appreciate help. Should be pretty easy for a knowledgeable coder based on Codex information I've read.
codex.wordpress.org/Function_Reference/WP_Rewrite
Thanks.
Viktor Nagornyy | 07/27/10 at 7:17pm
| Edit
(5) Possible Answers Submitted...
-

Last edited:
07/27/10
7:26pmPippin Williamson says:You could change your permalink settings to "/%postname%/" in Settings -> Pemalinks
- 07/27/10 7:30pm
Viktor Nagornyy says:That's what I have as my permalink structure. It still shows up. The sample.com/event_type/conventions points to an archive type page with a list of posts under that custom taxonomy. Not sure if that info helps.
- 07/27/10 7:30pm
-

Last edited:
07/27/10
7:44pmJarret Minkler says:http://www.deanlee.cn/wordpress/permalinks-migration-plugin/
Use the permalink migrator to safely migrate -

Last edited:
07/28/10
10:01amChris Olbekson says:To remove event_type from your permalink change your code to as follows:
<?php
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy( 'event_type', 'post', array( 'hierarchical' => true, 'label' => 'Event Type', 'query_var' => true, 'rewrite' => array( 'slug' => 'event_type', 'with_front' => false ) );
} ?>
NOTE: You may possibly need to click save on the permalink page after making the necessary code change.
Edit: I apologize. I left off the end parentheses after the array. This is the correct code:
<?php
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy( 'event_type', 'post', array( 'hierarchical' => true, 'label' => 'Event Type', 'query_var' => true, 'rewrite' => array( 'slug' => 'event_type', 'with_front' => false )) );
} ?>Previous versions of this answer: 07/28/10 at 12:35am | 07/28/10 at 10:01am
- 07/28/10 7:53am
Viktor Nagornyy says:Something about your code breaks the site, once I hit save it all goes to white screen and I have to ftp old version back in to fix it. So something's wrong.
- 07/28/10 10:50am
Viktor Nagornyy says:Still nothing, I always seems to find something ridiculous ha.
- 07/28/10 7:53am
-

Last edited:
07/28/10
12:58amRashad Aliyev says:Mr. Viktor Nagornyy,
I think you put this registering code to your default theme function. ( in functions.php ). So it changed your permalink structure. You should put it to your child theme functions. It'll register for your child theme and don't forget remove it from your default theme.
Then change your permalinks structure to default, then save and again change to what you prefer.
I think it'll help you.
best regards,- 07/28/10 7:54am
Viktor Nagornyy says:Hey,
I'm not quiet sure what you mean by child theme. If you could elaborate.
Thanks.
- 07/28/10 7:54am
-

Last edited:
07/28/10
2:05pmwjm says:Hi Viktor,
here is the code that does what you need.
add this line to your functions.php
it can go right bellow build_taxonomies()
require_once( TEMPLATEPATH . '/rewrite_rules_event_type.php');
and save the following file as "rewrite_rules_event_type.php" in the same dir as functions.php
http://wordpress.pastebin.com/SpxbmFgV
it will do the job.
I tested it locally.
after running for the first time, and having it to work,
comment this line
$flush_rules = TRUE;
to improve perfomance (that avoids having to update the rewrite rules to the database)
let me know if you need anything else.
- wjm
- 07/28/10 10:47am
Viktor Nagornyy says:I wish this would be that easy. For some reason it's not working. Does it matter how my taxonomy.php is structured?
This is what my functions.php looks like in case something in there matters. The new file is in the theme's dir. I even resaved permalinks to be certain.
<?php
define("INC", TEMPLATEPATH . "/functions");
require_once INC . "/wpzoom-functions.php";
require_once INC . "/wpzoom-core.php";
require_once INC . "/hidemenus.php";
/*Function to hide child category display if empty*/
function empty_dont_display_it($content) {
if (!empty($content)) {
$content = str_ireplace('<li>' .__( "No categories" ). '</li>', "", $content);
}
return $content;
}
add_filter('wp_list_categories','empty_dont_display_it');
//Function to check if a post is in a subcategory
function post_is_in_descendant_category( $cats, $_post = null )
{
foreach ( (array) $cats as $cat ) {
$descendants = get_term_children( (int) $cat, 'category');
if ( $descendants && in_category( $descendants, $_post ) )
return true;
} //end foreach
return false;
} //end function
?>
<?php
if ( !current_user_can( 'edit_users' ) ) {
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
}
?>
<?php
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
wp_add_dashboard_widget('custom_help_widget', 'Widget', 'custom_dashboard_help');
}
function custom_dashboard_help() {
echo '<p>Custom dashboard widget</p>';
}
?>
<?php
function custom_colors() {
echo '<style type="text/css">#wphead{background:#41474d; color:#ffffff !important;}</style>';
}
add_action('admin_head', 'custom_colors');
?>
<?php
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy( 'event_type', 'post', array( 'hierarchical' => true, 'label' => 'Event Type', 'query_var' => true, 'rewrite' => true ) );
}
require_once( TEMPLATEPATH . '/rewrite_rules_event_type.php');
?>
Thanks for your help. - 07/28/10 10:58am
wjm says:i think that's wrong.
you should move
<?php
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy( 'event_type', 'post', array( 'hierarchical' => true, 'label' => 'Event Type', 'query_var' => true, 'rewrite' => true ) );
}
require_once( TEMPLATEPATH . '/rewrite_rules_event_type.php');
?>
to your functions.php
located in your theme directory
that is wp-content/themes/YOUR_THEME_FOLDER/ - 07/28/10 11:06am
Viktor Nagornyy says:Hey,
I think you misunderstood me. That's exactly where it is. I copy and pasted my functions.php code above.
I was just simply asking about taxonomy.php, if the contents could break rewrite code. - 07/28/10 11:10am
wjm says:oh.. sorry, i misread that, i thought you pasted the contents of taxonomy.php
the first answer to your question is no, as the template loads after the rewrite rule is resolved.
can i have access to your server. it may be easier.
msg me with the wordpress and ftp info if you want to.
what happens when you enter
sample.com/conventions/
what is the url of your site? - 07/28/10 11:18am
Viktor Nagornyy says:Hmmmm thats interesting.
both URLs working, but the menu link keeps it as /event_type/convention
I'm using new nav_menu feature. Is there a way to make sure that /event_type/convention no longer works? It's going to be SEO problem being double content.
If you still need to look at it, I can provide you with my WP login to my test blog where I'm testing this, so you can use Editor to look at files.
Thanks. - 07/28/10 1:49pm
wjm says:I found the best way to deal with this.
forget about rewrite_rules_event_type.php
all the code you need is:
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy(
'event_type',
'post',
array(
'hierarchical' => true,
'label' => 'Event Type',
'query_var' => true,
'rewrite' => true,
)
);
global $wp_rewrite;
$wp_rewrite->extra_permastructs['event_type'] = array('%event_type%', EP_NONE);
}
there is a missing filter to alter the extra_permastructs, i am submitting a patch to wordpress trac.
i have fixed it in your blog.
you can check it.
- wjm - 07/28/10 2:01pm
Viktor Nagornyy says:Sweetness! Like I said in the another comment above, I always find something ridiculous. ha!
Thanks for your help. I appreciate. - 07/28/10 2:01pm
Viktor Nagornyy says:Sweetness! Like I said in the another comment above, I always find something ridiculous. ha!
Thanks for your help. I appreciate it.
- 07/28/10 10:47am
This question has expired.
Current status of this question: Completed




