Plugin Author
scribu
(@scribu)
Thread Starter
sdls
(@simon_said)
thanks for the ultra quick response Scribu! Can’t seem to find the answer on the page you’ve suggested
Are you suggesting I look at this tutorial?
http://matty.co.za/2009/11/custom-url-rewrites-in-wordpress/
Doesn’t seem to be the same requirements as what Rayken is looking for. I’m a bit of a newb to this topic, so please excuse my slowness in understanding
Any insight would be greatly appreciated.
Thread Starter
sdls
(@simon_said)
Rayken’s example is the closest I can find to a plug and play code. The key difference is in his example the first url chunk is fixed. i.e. ‘spare-parts/’ whereas I’m hoping to make this flexible.
// the rules
function custom_p2p_rewrites() {
global $wp_rewrite;
// Define custom rewrite tokens
$rewrite_tag = '%productName%';
// Add the rewrite tokens
$wp_rewrite->add_rewrite_tag( $rewrite_tag, '(.+?)', 'products=' );
// Define the custom permalink structure
$rewrite_keywords_structure = $wp_rewrite->root . "/spare-parts/$rewrite_tag/";
// Generate the rewrite rules
$new_rule = $wp_rewrite->generate_rewrite_rules( $rewrite_keywords_structure );
// Add the new rewrite rule into the global rules array
$wp_rewrite->rules = $new_rule + $wp_rewrite->rules;
return $wp_rewrite->rules;
}
// add to query vars
function add_custom_p2p_rewrites( $public_query_vars ) {
$public_query_vars[] = 'products';
return $public_query_vars;
}
// flush
function flush_custom_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_action( 'init', 'flush_custom_rules' );
add_action( 'generate_rewrite_rules', 'custom_p2p_rewrites' );
add_filter( 'query_vars', 'add_custom_p2p_rewrites' );
Thanks thanks thanks for your help