admin管理员组文章数量:1302268
Im trying this to show My CurrentPage (Licenciatura en Ciencias del Arte y Gestión Cultural.) child called "Infraestructura" by it's slug. I don't know whats wrong with my code. It Returns No PAGE. My guess is that pagename is not working...
<?php
$pageid = $post->ID;
$arg1 = array(
'post_type' => 'page',
'posts_per_page' => 1,
'post_parent' => $pageid,
'pagename' => 'infraestructura',
);
$child = new WP_Query( $arg1 ); ?>
<div class="wrapp">
<?php echo $pageid; ?>
<?php if ($child->have_posts()) :?>
<?php while ($child->have_posts()) : $child->the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php else: ?>
no page
<?php endif; wp_reset_postdata(); ?>
</div>
this is my page
NOTE: I have the same structure with multiple pages, this is WHY I need the SLUG or name to work
Im trying this to show My CurrentPage (Licenciatura en Ciencias del Arte y Gestión Cultural.) child called "Infraestructura" by it's slug. I don't know whats wrong with my code. It Returns No PAGE. My guess is that pagename is not working...
<?php
$pageid = $post->ID;
$arg1 = array(
'post_type' => 'page',
'posts_per_page' => 1,
'post_parent' => $pageid,
'pagename' => 'infraestructura',
);
$child = new WP_Query( $arg1 ); ?>
<div class="wrapp">
<?php echo $pageid; ?>
<?php if ($child->have_posts()) :?>
<?php while ($child->have_posts()) : $child->the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php else: ?>
no page
<?php endif; wp_reset_postdata(); ?>
</div>
this is my page
NOTE: I have the same structure with multiple pages, this is WHY I need the SLUG or name to work
Share Improve this question edited Mar 19, 2021 at 22:08 May Ornelas asked Mar 19, 2021 at 22:02 May OrnelasMay Ornelas 11 bronze badge1 Answer
Reset to default 0this is how i solved my problem:
<?php
$pageid = $post->ID;
$pageslug = $post->post_name;
$pos = $post->post_parent;
$posname = get_post_field( 'post_name', $pos );;
$arg1 = array(
'post_type' => 'page',
'posts_per_page' => 1,
'pagename' => $posname.'/'.$pageslug.'/infraestructura',
);
$child = new WP_Query( $arg1 ); ?>
<div class="wrapp">
<?php if ($child->have_posts()) :?>
<?php while ($child->have_posts()) : $child->the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php else: ?>
no page
<?php endif; wp_reset_postdata(); ?>
</div>
本文标签: wp queryShow child by slugwhile knowing parent ID
版权声明:本文标题:wp query - Show child by slug, while knowing parent ID 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741667387a2391394.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论