admin管理员组

文章数量:1196987

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>

本文标签: custom post typesWP queryposts group by meta field related