$mergedterms = array_unique(array_merge($series_terms, $genres_terms, $rating_terms), SORT_REGULAR);
foreach($mergedterms as $mergedterm){
$args2 = array(
'post_type'=>
array('progressive_review', 'game_information','gaming_series', 'dlc_title'),
'posts_per_page' => 10,
'post_status' => 'publish',
'orderby' => 'rand',
'post__not_in' => array($currentID, $gametitleID),
'tax_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'taxonomy' => 'games_titles',
'field' => 'slug',
'terms' => array ($term->name),
),
array(
'taxonomy' => 'gaming_genres',
'field' => 'slug',
'terms' => array ($mergedterm->name),
),
array(
'taxonomy' => 'game_ratings',
'field' => 'slug',
'terms' => array ($mergedterm->name),
),
array(
'taxonomy' => 'gaming_series',
'field' => 'slug',
'terms' => array ($mergedterm->name),
),
), array(
'taxonomy' => 'age_ratings',
'field' => 'slug',
'terms' => $age_terms,
),
),/*Search above post type for taxonomy and if matches then proceed*/
); }
$the_query = new WP_Query($args2);
if($the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
php bm_ignorePost($post->ID);
php endwhile; else:
php endif; wp_reset_postdata();
在发现很多其他问题后,我现在回到同一个问题。因此,我删除了帖子并更新了代码。
简单地说,我不能为我的生活得到'或'的数组,但将$ age_terms视为'AND'。肯定有一个简单的方法来实现这一目标吗?保持听力array_intersect相当慢,因为速度就是一切。这就是为什么我尝试了多种方法,却看不出为什么它不能在同一个数组中处理?
Array
(
[post_type] => Array
(
[0] => progressive_review
[1] => game_information
[2] => gaming_series
[3] => dlc_title
)
[posts_per_page] => 10
[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] => gaming_genres
[field] => slug
[terms] => Array
(
[0] => Violence
)
)
[2] => Array
(
[taxonomy] => game_ratings
[field] => slug
[terms] => Array
(
[0] => Violence
)
)
[3] => Array
(
[taxonomy] => gaming_series
[field] => slug
[terms] => Array
(
[0] => Violence
)
)
[4] => Array
(
[taxonomy] => age_ratings
[field] => slug
[terms] => Array
(
[0] => 3pegi
[1] => 7pegi
)
)
)
)
age_terms来自
<?php if (has_term('7pegi', 'age_ratings', $post->ID)){
$age_terms = array('3pegi', '7pegi'); }?>
引入了一个数组var来修复合并问题意味着更好的相关性。
$genres_sorted = array();
foreach($genres_terms as $genres_term) {
$genres_sorted[] = $genres_term;
}