I have created a small segment within WordPress that records match information for League of Legends. Using up to 30 different custom fields I can store information of 30 champions picked from 3 games (10 different champions are picked each game)
I want to query all games the champion 'Shen' has played in but the issue have come across is, if 'shen' was Picked in two of the three games played, that individual match is displayed twice in the loop. Is it possible to prevent any duplicates if a custom field has duplication information?
Code I am using currently:
<?php
$querystr = "
SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->postmeta.meta_value = 'Shen'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'matches'
AND $wpdb->posts.post_date < NOW()
ORDER BY $wpdb->posts.post_date DESC
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
?>
<?php if ($pageposts): ?>
<?php global $post; ?>
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<div class="matchesh">
<div class="vs">vs</div>
<div class="vdetails"><a href="<?php the_permalink(); ?>">view match information</a></div>
<div class="vevent"><?php echo get_post_meta($post->ID, 'dbt_tournamentname', true) ?></div>
<div class="teamleft"><img src="<?php echo get_post_meta($post->ID, 'dbt_team1logo', true) ?>" /></div>
<div class="teamright"><img src="<?php echo get_post_meta($post->ID, 'dbt_team2logo', true) ?>" /></div>
<div class="clearfix"></div>
</div>
<?php endforeach; ?>
<?php else : ?>
<h2 class="center">No matches found featuring 'Shen'.</h2>
<p class="center">Sorry, no team composition featured the selected champion.</p>
<?php endif; ?>
Any help will be greatly appreciated! Cheers Dan
WP_Query
instance or modifying the main query viapre_get_posts
?