Post türlerinden farklı olarak, WordPress'in taksonomi sümükünün kendisi için bir yolu yoktur. ` 'Sınıflandırmasında' => '$ ile on line
// Register a taxonomy 'location' with slug '/location'.
register_taxonomy('location', ['post'], [
'labels' => [
'name' => _x('Locations', 'taxonomy', 'mydomain'),
'singular_name' => _x('Location', 'taxonomy', 'mydomain'),
'add_new_item' => _x('Add New Location', 'taxonomy', 'mydomain'),
],
'public' => TRUE,
'query_var' => TRUE,
'rewrite' => [
'slug' => 'location',
],
]);
// Register the path '/location' as a known route.
add_rewrite_rule('^location/?$', 'index.php?taxonomy=location', 'top');
// Use the EXISTS operator to find all posts that are
// associated with any term of the taxonomy.
add_action('pre_get_posts', 'pre_get_posts');
function pre_get_posts(\WP_Query $query) {
if (is_admin()) {
return;
}
if ($query->is_main_query() && $query->query === ['taxonomy' => 'location']) {
$query->set('tax_query', [
[
'taxonomy' => 'location',
'operator' => 'EXISTS',
],
]);
// Announce this custom route as a taxonomy listing page
// to the theme layer.
$query->is_front_page = FALSE;
$query->is_home = FALSE;
$query->is_tax = TRUE;
$query->is_archive = TRUE;
}
}
yukarıdaki örneği:
taksonomisi sülük kendisi taxonominin herhangi bir terim atanmış tüm mesajları listelemek yapmak için,EXISTS
operator oftax_query
inWP_Query
kullanmak gerekir term_name '' bu tür 'taksonomi' => "$ term_adı" 'şeklinde çift tırnaklı olmalı veya bu tür '' taksonomi '=> $ term_adı' gibi daha iyi tırnaklar yoksa veya daha önce atamayı atlayıp daha iyi kullanmalısınız 'taxonomy' => $ term-> slug'. Dedi ki, gösterilen yöntem ['tax_query' => array (...) 'kullanarak [http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters] lehine [kullanımdan kaldırılmıştır]. Bu yardımcı olur umarım. – MikeSchinkelÜzgünüm, gecikme ... haklısın. Cevabımı buna göre değiştirdim :) –
Mükemmel! Birlikte umarım çabalarımız başkalarına yardım eder. – MikeSchinkel