我有在不同页面中使用的条款和条件。现在,我要根据条款和条件列出页面。所以我想获得特定条款和条件(分类法)的页面。需要您的帮助。我浏览了一些博客,我明白了。
$product_page_args = array(
'post_type' => 'page',
'order' => 'ASC',
'orderby' => 'menu_order',
'child_of' => $post_id,
'taxonomy' => 'term-condition',
'field' => 'slug',
'term' => 'ID'
);
$product_pages = new WP_Query($product_page_args);
foreach ($product_pages as $product_page){
echo $product_page->post_title;
}
答案 0 :(得分:0)
我将分享类似的代码。我的代码在分类模板website.com/{taxonomy-slug}/{term-slug}
上列出了给定分类的所有页面。
$taxonomy = get_query_var( 'taxonomy' );
$tax_term = get_query_var( 'term' );
// get all post types for tax term
$posts_list = new WP_Query(array(
'post_status' => 'publish',
'post_type' => 'page',
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $tax_term,
),
),
'fields' => 'ids',
'posts_per_page' => -1,
'nopaging' => true
));
在您的情况下,将是这样的:
$posts_list = new WP_Query(array(
'post_status' => 'publish',
'post_type' => 'page',
'tax_query' => array(
array(
'taxonomy' => 'term-condition',
'field' => 'slug',
'terms' => 'ID',
),
),
'fields' => 'ids',
'posts_per_page' => -1,
'nopaging' => true
));
鉴于“ ID”是分类法“期限条件”的术语。如果是这样,我会重新考虑这个名称,因为很容易将ID作为发布对象的属性来混淆。
希望对您有帮助。