我的wordpress网站有点问题。我需要更改用户永久链接。permalinks应该包含来自wp\\u usermeta表的数据。我做了一些功能,链接也更改了,但当我访问它们时,它会显示:找不到页面。如果你能告诉我我的密码出了什么问题,我就请你喝杯啤酒。代码如下:
add_filter( \'request\', \'wpse5742_request\' );
function wpse5742_request( $query_vars )
{
if ( array_key_exists( \'author_name\', $query_vars ) ) {
global $wpdb;
$author_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key=\'nickname\' AND meta_value = %s", $query_vars[\'author_name\'] ) );
$query_vars[\'author\'] = $author_id;
unset( $query_vars[\'author_name\'] );
}
return $query_vars;
}
add_filter( \'author_link\', \'wpse5742_author_link\', 10, 3 );
function wpse5742_author_link( $link, $author_id, $author_nicename )
{
$part1 = get_user_meta( $author_id, \'nickname\', true );
$part2 = get_user_meta( $author_id, \'_themex_city\', true );
$part3 = get_user_meta( $author_id, \'_themex_thesubject\', true );
$newlink = $part1.\'/\'.$part2.\'/\'.$part3;
if ( $newlink ) {
$link = str_replace( $author_nicename, $newlink, $link );
}
return $link;
}
add_action( \'user_profile_update_errors\', \'wpse5742_set_user_nicename_to_nickname\', 10, 3 );
function wpse5742_set_user_nicename_to_nickname( &$errors, $update, &$user )
{
if ( ! empty( $user->nickname ) ) {
$user->user_nicename = sanitize_title( $user->nickname, $user->display_name );
} }
我要创建的永久链接是:example.com/username/city/occupation