簡體   English   中英

在wordpress中返回所有自定義分類ID的帖子

[英]Return all posts for a custom taxonomy id in wordpress

我有此代碼應返回與分類法ID相關的所有帖子,但它返回最后5個帖子。

<?php 
$leaderships = new WP_Query(array(
'post_type'      => 'leadership',
'posts_per_page' => 11,
'tax_query'      => array(
    array(
        'taxonomy' => 'leadership-committee', 
        'field'    => 'id',
        'terms'    => 13,
    ),
),
));
?>

posts_per_page在這里不起作用,獲取所有帖子的任何幫助。

謝謝

嘗試測試最簡單的方法:

<?php 
$leaderships = new WP_Query(array(
'post_type'      => 'leadership',
'posts_per_page' => -1
));
?>

如果它返回“ leadership”自定義帖子類型的所有帖子,則使用“ tax_query”將其縮小,並檢查在其創建的自定義分類法中是否有5個以上的自定義帖子類型“ leadership”條目屬於“ leadership-committee” ID為13的孩子(類別/標簽之類)

除此之外,所有查詢都可以。

感謝每個人的幫助,我發現問題出在我的主題管理區域,該區域將帖子限制為5個,現在已修復。

這是上述問題的答案...

$args = array('post_type' => 'product',
    'tax_query' => array(
        array(
            'taxonomy' => 'product_cat',
            'field' => 'term_id',
            'terms' => 619,
        ),
    ),
 );

 $loop = new WP_Query($args);
 if($loop->have_posts()) {
    echo '<h2>'.$custom_term->name.'</h2>';

    while($loop->have_posts()) : $loop->the_post();
        echo '<a href="'.get_permalink().'">'.get_the_title().'</a>'."<br/>";
    endwhile;
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM