我想列出由父帖订购的最新儿童关联帖子。可能吗?有人可以帮我吗?我用一个例子来解释:假设我有Dramas自定义帖子类型和Episode自定义帖子类型,它们连接到帖子2帖子。在戏剧档案中,我想列出他们最新一集的所有剧集,并且只想在循环中播放一集。
我认为有可能使用each_connected(),但我不知道如何订购$ wp_query数组来完成这项工作。
感谢。
我现在正在使用这种代码
<?php
global $post;
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$anime_series = array(
'post_type' => 'drama',
'posts_per_page' => 12,
'paged' => $paged,
'page' => $paged,
'post_status' => 'publish',
'orderby' => 'post_date',
'order' => 'DESC'
);
$the_query = new WP_Query( $anime_series);
$extra = array(
'posts_per_page' => 1,
'post_status' => 'publish',
'orderby' => 'post_date',
'order' => 'DESC'
);
p2p_type( 'drama_to_episode' )->each_connected( $the_query, $extra, 'episode' );
?>
</div>
<div class="last_episodes loaddub">
<ul class="items">
<?php if ( $the_query->have_posts() ) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<li>
<div class="img"> <a href="<?php echo the_permalink(); ?>" title="<?php echo the_title(); ?>"> <img alt="<?php echo the_title(); ?>" itemprop="photo" src="<?php echo get_the_post_thumbnail_url(); ?>"> </a>
<div class="type"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/SUB.png"></div>
</div>
<?php
foreach ( $post->episode as $post ) : setup_postdata( $post ); ?>
<p class="name"> <a href="<?php echo the_permalink(); ?>" title="<?php echo get_the_title($items['parent']); ?>"> <?php echo get_the_title($items['parent']); ?> </a> </p>
<p class="episode"> <?php echo the_field('short_name'); ?> </p>
<?php
endforeach;
?>
</li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p>
<?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?>
</p>
<?php endif; ?>
</ul>
</div>
答案 0 :(得分:0)
试试这个简单的例子
?php
$args = array(
'post_parent' => 38,
'post_type' => 'page',
'numberposts' => -1,
'post_status' => 'any'
);
$children = get_children( $args );
foreach($children as $post):
echo $post->post_title;
endforeach;
?>
希望能按照你的要求工作!!!
答案 1 :(得分:0)
global $post, $items, $wpdb;
$table_name = $wpdb->prefix . "p2p";
$query = 'SELECT p2p_from as anime, max(p2p_to) as episode FROM '.$table_name;
$results = $wpdb->get_results( $query.' GROUP BY p2p_from ORDER BY episode DESC' );
然后,在foreach循环中,我通过ID检索了帖子标题,永久链接等。