[英]How can i get all post of taxonomy category post by taxonomy category id or taxonomy category name in wordPress?
我創建了post類型的產品,還創建了名為productcategory的分類法。 現在我需要在相關產品中獲得特定類別。 不知何故,我設法通過使用找到分類法類別ID和名稱
$term_list = wp_get_post_terms($post->ID, 'productcategory', array("fields" => "ids"));
現在,我如何獲得該分類學類別的所有帖子?
顯示與某些分類相關的帖子。 如果指定注冊到自定義帖子類型的分類法,則不使用“類別”,而是使用“{custom_taxonomy_name}”。 例如,如果你有一個名為“genre”的自定義分類,並且只想顯示“jazz”類型的帖子,你可以使用下面的代碼。
<?php
$args = array(
'posts_per_page' => 8,
'orderby' => 'rand',
'post_type' => 'products',
'productcategory' => 'your_cat_name',
'post_status' => 'publish'
);
$show_albums = get_posts( $args );
?>
$terms = get_the_terms( $post->ID, 'productcategory' );
$args = array(
'post_type' => 'products',
'tax_query' => array(
array(
'taxonomy' => 'productcategory',
'field' => 'slug',
'terms' => explode(',',$terms),
),
),
);
$query = new WP_Query( $args );
然后使用此查詢的結果運行循環,你應該好好去!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.