I think it will be better to create a custom post type for partners, called “partner”.
Thread Starter
Adan0s
(@adan0s)
Sure, the whole thing would probably much more cleaner with a custom post type. But in that case I would need to create a whole plugin out of that small script. 😐
Currently I have my profiles in an independent database which I simply query via wpdb.
I think I’ll simply go with the .htaccess-solution until my client approves the budget for converting it into a plugin.
Adan0s, did you ever figure out a way to do this?
Thread Starter
Adan0s
(@adan0s)
Hey mavrick,
yes, even though it’s a combination of a modificated page-template, an addition to the functions.php and a custom table in the wordpress-database
functions.php (put at the end)
add_filter('query_vars', 'partner_queryvars' );
function partner_queryvars( $qvars )
{
$qvars[] = 'slug';
return $qvars;
}
add_action('generate_rewrite_rules', 'partner_add_rewrite_rules');
function partner_add_rewrite_rules( $wp_rewrite )
{
$new_rules = array(
'partner/([^/]*)$' => 'index.php?pagename=partner&slug=' .$wp_rewrite->preg_index(1) );
//Add the new rewrite rule into the top of the global rules array
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
page-partner.php (put at top)
$slug = get_query_var('slug');
if($slug != "") {
$partner = $wpdb->get_row($wpdb->prepare("SELECT * FROM partner WHERE slug=%s LIMIT 1",$slug));
}
else {
// no slug, do something generic
}
the custom table (in my case called partner) has multiple rows, one of them called slug includes the desired part of the url.
code should be pretty self-explanatory, just replace partner with your page and slug with your desired variable. if not, don’t hesitate to ask.
Adan0s, thank you for the quick response. I will be trying this out this week.