我的最后一个阵列仍然没有成功,或者从之前被删除的问题中获得回复。
出于某种原因,尽管我解决了我的问题,但阵列无法继续进行。撕开之后我把它缩小到了这些。
<?php foreach($age_terms as $age_term){?>
_
<?php $args3 = array(
'post_type'=>
array('game_information', 'gaming_series', 'dlc_title'),
'posts_per_page' => 10,
'post_status' => 'publish',
'orderby' => 'rand',
'post__not_in' => array($currentID),
'tax_query' => array(
'taxonomy' => 'age_ratings',
'field' => 'slug',
'terms' => array ($age_term->name),
),
); ?>
_
<?php var_dump($args3); $the_query = new WP_Query($args3);
if($the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php endwhile; else: ?>
<?php endif; wp_reset_postdata(); } ?>
var_dump返回:
Array(6)
(
[post_type] => Array
(
[0] => game_information
[1] => gaming_series
[2] => dlc_title
)
[posts_per_page] => 10
[post_status] => publish
[orderby] => rand
[post__not_in] => Array
(
[0] =>
)
[tax_query] => Array
(
[taxonomy] => age_ratings
[field] => slug
[terms] => Array
(
[0] =>
)
)
)
这似乎是个问题。该数组设置为:
<?php if (has_term('7pegi', 'age_ratings', $post->ID)){
$age_terms = array('3pegi', '7pegi'); }?>
这是另一个回到页面顶部的循环,它获取了该帖子的条款。
我的计划是将这些用作术语,然后在最终数组中使用。 然后使用$ age_term数组删除没有术语3pegi + 7pegi的条目。
但遗憾的是,由于这一部分似乎严重受损,我真的需要在继续之前就错误提出一些建议。谢谢。 的更新 结果是如此接近,直到我分开条款以获得更好的结果。
$rating_terms = get_the_terms($post->ID, 'game_ratings');
进入
$ratings_sorted = array();
foreach ($rating_terms as $rating_term){
$ratings_sorted[] = $rating_term;
}
然后用作
$args2 = array(
'post_type'=>
array('progressive_review', 'game_information','gaming_series', 'dlc_title'),
'posts_per_page' => 20,
'post_status' => 'publish',
'orderby' => 'rand',
'post__not_in' => array($currentID, $gametitleID),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'games_titles',
'field' => 'slug',
'terms' => array ($game_term->name)
), array(
'taxonomy' => 'game_ratings',
'field' => 'slug',
'terms' => array ($ratings_sorted->name)
),
),/*Search above post type for taxonomy and if matches then proceed*/
);
返回
print "<pre>".print_r($args2, true)."</pre>";
Array
(
[post_type] => Array
(
[0] => progressive_review
[1] => game_information
[2] => gaming_series
[3] => dlc_title
)
[posts_per_page] => 20
[post_status] => publish
[orderby] => rand
[post__not_in] => Array
(
[0] => 1958
[1] => 1623
)
[tax_query] => Array
(
[relation] => OR
[0] => Array
(
[taxonomy] => games_titles
[field] => slug
[terms] => Array
(
[0] => Sonic Lost World
)
)
[1] => Array
(
[taxonomy] => game_ratings
[field] => slug
[terms] => Array
(
[0] =>
)
)
)
)
print "<pre>".print_r($ratings_sorted, true)."</pre>";
Array
(
[0] => stdClass Object
(
[term_id] => 25
[name] => Online
[slug] => online
[term_group] => 0
[term_taxonomy_id] => 62
[taxonomy] => game_ratings
[description] =>
[parent] => 0
[count] => 5
[object_id] => 1623
)
[1] => stdClass Object
(
[term_id] => 45
[name] => Violence
[slug] => violence
[term_group] => 0
[term_taxonomy_id] => 45
[taxonomy] => game_ratings
[description] =>
[parent] => 0
[count] => 5
[object_id] => 1623
)
)
读取stdClass但似乎不起作用。尽管标题术语在单独使用时工作正常。问题似乎是在尝试将多个术语处理回可用数组时。
编辑 尽可能清楚,我真正需要的是抓住[slug]并使用这些词。别无其他。
*想想我已经使用wp_list_pluck解决了它 在第一个循环中
<?php $gametitleID = get_the_ID(); ?>
然后在需要之前进行外循环。
$rating_terms = get_the_terms($gametitleID, 'game_ratings' );
$rating_con = wp_list_pluck( $rating_terms, 'slug' );
允许将其用作
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'games_titles',
'field' => 'slug',
'terms' => $game_con,
), array(
'taxonomy' => 'gaming_genres',
'field' => 'slug',
'terms' => $genres_con,
将继续测试。