如果有人仍在搜索此问题。。。将帖子的永久链接设置更改为;物品名称“;(site.com/name-article)为我修复了这个问题。
我也在函数中使用此代码。php:
add_filter(\'request\', function( $vars ) {
global $wpdb;
if(isset($vars[\'error\'])){
$lastVar = basename($_SERVER[\'REQUEST_URI\']);
$vars[\'attachment\'] = $lastVar;
}
if( ! empty( $vars[\'pagename\'] ) || ! empty( $vars[\'category_name\'] ) || ! empty( $vars[\'name\'] ) || ! empty( $vars[\'attachment\'] ) ) {
$slug = ! empty( $vars[\'pagename\'] ) ? $vars[\'pagename\'] : ( ! empty( $vars[\'name\'] ) ? $vars[\'name\'] : ( !empty( $vars[\'category_name\'] ) ? $vars[\'category_name\'] : $vars[\'attachment\'] ) );
$exists = $wpdb->get_var( $wpdb->prepare( "SELECT t.term_id FROM $wpdb->terms t LEFT JOIN $wpdb->term_taxonomy tt ON tt.term_id = t.term_id WHERE tt.taxonomy = \'product_cat\' AND t.slug = %s" ,array( $slug )));
if( $exists ){
$old_vars = $vars;
$vars = array(\'product_cat\' => $slug );
if ( !empty( $old_vars[\'paged\'] ) || !empty( $old_vars[\'page\'] ) )
$vars[\'paged\'] = ! empty( $old_vars[\'paged\'] ) ? $old_vars[\'paged\'] : $old_vars[\'page\'];
if ( !empty( $old_vars[\'orderby\'] ) )
$vars[\'orderby\'] = $old_vars[\'orderby\'];
if ( !empty( $old_vars[\'order\'] ) )
$vars[\'order\'] = $old_vars[\'order\'];
}
}
return $vars;
});
add_filter(\'term_link\', \'term_link_filter\', 10, 3);
function term_link_filter( $url, $term, $taxonomy ) {
$url=str_replace("/./","/",$url);
return $url;
}