[英]Show posts from specific category - Wordpress array
我的模板選項上有這個數組:
$args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'ignore_sticky_posts' => 1,
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array('post-format-quote', 'post-format-link', 'post-format-audio'),
'operator' => 'NOT IN',
'category_name' => 'noticias'
)
),
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_thumbnail_id',
'compare' => 'EXISTS'
),
array(
'key' => 'MEDICAL_META_embed_code',
'compare' => 'EXISTS'
),
array(
'key' => 'MEDICAL_META_gallery',
'compare' => 'EXISTS'
)
)
);
如果您看到'category_name' => 'noticias'
,noticias是我要在主頁上顯示的類別,但是該行不起作用,也許'category_name'不是這里的最佳選擇...
我讀過wordpress文檔,但是沒有數組示例,只有函數,有沒有辦法在這樣的數組上完成此操作?
提前致謝!
對於特定類別的顯示帖子,您可以使用WP Query
功能,有關此功能,請參見鏈接
為了使閱讀此線程的人受益,您可以使用以下參數過濾查詢args數組中的特定類別
cat (int) - use category id.
category_name (string) - use category slug (NOT name).
category__and (array) - use category id.
category__in (array) - use category id.
category__not_in (array) - use category id.
只需修改數組即可解決OP的問題,如下所示
$args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'ignore_sticky_posts' => 1,
'cat' => '777' // Put the cat ID here
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
...
...
)
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.