Vytvořil jsem jednoduchou smyčku. Pro dotaz mám následující pole:
$live_tags = array(
'tag' => 'live',
'showposts' => 5,
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC'
);
Kde se říká 'tag' => 'live'
, potřebuji logiku, která se ptá:
if ('tag' == 'live' || 'category' == 'candy')
Ale nejsem si jistý, jak to udělat v poli WP_Query.
Každý, kdo ví, jak načíst příspěvky z jedné značky nebo kategorie?
Potřebujete tax_query
.
$live_tags = array(
'posts_per_page' => 5, // showposts has been deprecated for a long time
'post_type' => 'post',
'post_status' => 'publish',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => 'live',
),
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'candy',
),
),
'orderby' => 'date',
'order' => 'DESC'
);
$q = new WP_Query($live_tags);
var_dump($q->request);
Argumenty {tax} (string)
a showposts
jsou již delší dobu zastaralé. Nedoporučoval bych je používat.