因此,我有一个自定义分类法(称为“版本”),用于posts wich工作正常。。我的问题是,我想在我的永久收入中使用这种税,例如URL.com/12-3/cat/postname
.. 这对posts 当我使用/%version%/%category%/%postname%/
对于permalinks。
但现在每pages 向我抛出404错误。。(例如URL.com/test->404)。如果我删除/%version%
很好用。。但只是为了书页。。但是我需要在URL中为帖子添加版本税。。下面的代码用于permalinks中的税务段塞:
add_filter(\'post_link\', \'version_permalink\', 10, 3);
function version_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, \'%version%\') === FALSE) {
return $permalink;
} else {
// Get post
$post = get_post($post_id);
if (!$post || \'page\' === $post->post_type) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, \'version\');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) {
$taxonomy_slug = $terms[0]->slug;
} else { $taxonomy_slug = \'no-version\'; }
return str_replace(\'%version%\', $taxonomy_slug, $permalink);
}
}
我想我犯了一些我不知道的愚蠢错误。。当我看到var\\u转储时(wp美元);它向我显示了例如(对于URL.com/impressum):
["query_vars"]=>
array(1) {
["version"]=>
string(9) "impressum"
}
["query_string"]=>
string(17) "version=impressum"
["request"]=>
string(9) "impressum"
["matched_rule"]=>
string(10) "([^/]+)/?$"
["matched_query"]=>
string(17) "version=impressum"
["did_permalink"]=>
bool(true)
因此“
version“thingy刚刚注册
posts 不
pages 但它仍在查找。。。我没有任何线索来解决这个问题,非常感谢您的帮助或更多见解:-)
仅供参考自定义分类法:
add_action(\'init\', \'version_init\');
function version_init() {
if (!is_taxonomy(\'version\')) {
$labels = array(
\'name\' => __( \'Versionen\'),
\'singular_name\' => __( \'Version\'),
\'search_items\' => __( \'Versionen suchen\' ),
\'popular_items\' => __( \'Oft genutzte Versionen\' ),
\'all_items\' => __( \'Alle Versionen\' ),
\'parent_item\' => null,
\'parent_item_colon\' => null,
\'edit_item\' => __( \'Version bearbeiten\' ),
\'update_item\' => __( \'Version aktualisieren\' ),
\'add_new_item\' => __( \'Neue Version hinzufuegen\' ),
\'new_item_name\' => __( \'Neue Version hinzufuegen\' ),
\'add_or_remove_items\' => __( \'Version hinzufuegen oder bearbeiten\' ),
\'choose_from_most_used\' => __( \'Die meistgenutzte Versionen aussuchen\' ),
\'not_found\' => __( \'Keine Versionen gefunden.\' ),
\'menu_name\' => __( \'Versionen\' ),
);
$rewrite = array(
\'slug\' => \'\',
\'with_front\' => false,
\'hierarchical\' => false,
);
register_taxonomy( \'version\', \'post\',
array(
\'hierarchical\' => TRUE,
\'labels\' => $labels,
\'public\' => TRUE,
\'show_ui\' => TRUE,
\'show_admin_column\' => TRUE,
\'update_count_callback\' => \'_update_post_term_count\',
\'query_var\' => \'version\',
\'rewrite\' => $rewrite
)
);
}
}