So I’ve received a customized taxonomy (referred to as “model”) for simply posts wich works positive.. My Drawback is that i wish to use this tax in my permalinks eg URL.com/12-3/cat/postname
.. which works additionally positive for the posts when i take advantage of /%model%/%class%/%postname%/
for the permalinks.
BUT now each pages throws me an 404 error.. (eg URL.com/check -> 404). If i take away /%model%
it really works positive.. however only for the pages.. however i want the model tax within the URL for the posts.. The Code beneath is used for the tax slugs within the permalinks:
add_filter('post_link', 'version_permalink', 10, 3);
operate version_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%model%') === FALSE) {
return $permalink;
} else {
// Get submit
$submit = get_post($post_id);
if (!$submit || 'web page' === $post->post_type) return $permalink;
// Get taxonomy phrases
$phrases = wp_get_object_terms($post->ID, 'model');
if (!is_wp_error($phrases) && !empty($phrases) && is_object($phrases[0])) {
$taxonomy_slug = $phrases[0]->slug;
} else { $taxonomy_slug = 'no-version'; }
return str_replace('%model%', $taxonomy_slug, $permalink);
}
}
I assume i made some silly error i am not conscious of.. When i seemed on the var_dump($wp); it exhibits me eg (for URL.com/impressum):
["query_vars"]=>
array(1) {
["version"]=>
string(9) "impressum"
}
["query_string"]=>
string(17) "model=impressum"
["request"]=>
string(9) "impressum"
["matched_rule"]=>
string(10) "([^/]+)/?$"
["matched_query"]=>
string(17) "model=impressum"
["did_permalink"]=>
bool(true)
so the “model” thingy is simply registered for posts not pages however its nonetheless wanting it up… I’ve received no clue to resolve this, any assist or some extra insights are a lot appreciated 🙂
fyi the customized taxonomy:
add_action('init', 'version_init');
operate version_init() {
if (!is_taxonomy('model')) {
$labels = array(
'identify' => __( 'Versionen'),
'singular_name' => __( 'Model'),
'search_items' => __( 'Versionen suchen' ),
'popular_items' => __( 'Oft genutzte Versionen' ),
'all_items' => __( 'Alle Versionen' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Model bearbeiten' ),
'update_item' => __( 'Model aktualisieren' ),
'add_new_item' => __( 'Neue Model hinzufuegen' ),
'new_item_name' => __( 'Neue Model hinzufuegen' ),
'add_or_remove_items' => __( 'Model 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( 'model', 'submit',
array(
'hierarchical' => TRUE,
'labels' => $labels,
'public' => TRUE,
'show_ui' => TRUE,
'show_admin_column' => TRUE,
'update_count_callback' => '_update_post_term_count',
'query_var' => 'model',
'rewrite' => $rewrite
)
);
}
}