Hello Guys i am trying to customize a wordpress theme and am getting this is How it queries All Posts with episodes post_type.
My Question Is.
this Post type is related to another post_type which is called tvshows so each post in that is post_type epsidoes has a meta_field called series which specifies the tvshow this postis related to.
for example There is series one post
which is post_type = tvshows
it's id is 20
and there are 2 posts in post_type = episodes, both these posts have meta_feild called series and both are related to the tvshow above so they have there meta_field series=20 which is the id of tvshow post type.
The problem in my query below is it shows all post in the post type episodes and i want it to show related posts once for example if 2 posts which are epsidoes share 1 tvshow i want to show them once like on database we use group by right but then i want to show the latest by date or name
so basically am saying i want to display all episode posts but latest once group by meta field series or show post which have same meta field once
// Compose Query
$query = array(
'post_type' => array('episodes'),
'showposts' => 10,
'orderby' => 'date',
'order' => 'DESC'
);
<div <?php if($slid) echo 'id="dt-episodes" '; ?>class="animation-2 items <?php echo $maxwidth; ?>">
<?php query_posts($query); while(have_posts()){ the_post(); get_template_part('inc/parts/item_ep'); } wp_reset_query(); ?>
</div>
query_posts
, useWP_Query
instead for secondary loops, andpre_get_posts
for the main loop. Both have better documentation, fewer pitfalls, and are easier to debug. There are very few times thatquery_posts
is appropriate, and as a plugin or theme developer it's not worth the trouble to use itpre_get_posts
filter that lets you modify the parameters of the main query eliminating the need for a second query and improving performance developer.wordpress.org/reference/hooks/pre_get_posts. Also keep in mind that these are comments on the question, I have not posted an answer/solution, the answers appear below in larger text with voting controls