admin管理员组文章数量:1130349
I am currently trying to grab a child page id from a custom post type, but my values returned are always null. I know that the particular ID I'm passing has a parent so there should be a match.
What is the appropriate way to grab child ids using the parent id?
This is what I have tried:
$parentid = $order->get_id();
$args = array(
'post_parent' => $parentid,
'post_type' => 'shop_subscription'
);
$child = new WP_Query($args);
if ($child->have_posts()) : while ($child->have_posts()) : $child->the_post();
$childid = get_the_id();
endwhile;
else:
$childid = "not set";
endif;
I am currently trying to grab a child page id from a custom post type, but my values returned are always null. I know that the particular ID I'm passing has a parent so there should be a match.
What is the appropriate way to grab child ids using the parent id?
This is what I have tried:
$parentid = $order->get_id();
$args = array(
'post_parent' => $parentid,
'post_type' => 'shop_subscription'
);
$child = new WP_Query($args);
if ($child->have_posts()) : while ($child->have_posts()) : $child->the_post();
$childid = get_the_id();
endwhile;
else:
$childid = "not set";
endif;
Share
Improve this question
asked Nov 16, 2017 at 0:25
elkefreedelkefreed
3851 gold badge5 silver badges16 bronze badges
2
- The accepted answer here stackoverflow/a/43164688/648252 is what finally helped me solve my issue. – elkefreed Commented Nov 16, 2017 at 18:20
- use this : codex.wordpress/Function_Reference/get_children – Jignesh Patel Commented Aug 1, 2018 at 13:40
1 Answer
Reset to default 2This should work. I'm not entirely sure what is wrong with your code (it's getting late) but the below code works on my end. Obviously I replaced $order->get_id() with a known ID and post_type was set to page.
<?php
$parentid = $order->get_id();
$child = new WP_Query( array('post_parent' => $parentid, 'post_type' => 'shop_subscription') );
if ($child->have_posts()) : while ($child->have_posts()) : $child->the_post();
$childid = get_the_ID();
endwhile;
else:
$childid = "not set";
endif;
wp_reset_query();
?>
I am currently trying to grab a child page id from a custom post type, but my values returned are always null. I know that the particular ID I'm passing has a parent so there should be a match.
What is the appropriate way to grab child ids using the parent id?
This is what I have tried:
$parentid = $order->get_id();
$args = array(
'post_parent' => $parentid,
'post_type' => 'shop_subscription'
);
$child = new WP_Query($args);
if ($child->have_posts()) : while ($child->have_posts()) : $child->the_post();
$childid = get_the_id();
endwhile;
else:
$childid = "not set";
endif;
I am currently trying to grab a child page id from a custom post type, but my values returned are always null. I know that the particular ID I'm passing has a parent so there should be a match.
What is the appropriate way to grab child ids using the parent id?
This is what I have tried:
$parentid = $order->get_id();
$args = array(
'post_parent' => $parentid,
'post_type' => 'shop_subscription'
);
$child = new WP_Query($args);
if ($child->have_posts()) : while ($child->have_posts()) : $child->the_post();
$childid = get_the_id();
endwhile;
else:
$childid = "not set";
endif;
Share
Improve this question
asked Nov 16, 2017 at 0:25
elkefreedelkefreed
3851 gold badge5 silver badges16 bronze badges
2
- The accepted answer here stackoverflow/a/43164688/648252 is what finally helped me solve my issue. – elkefreed Commented Nov 16, 2017 at 18:20
- use this : codex.wordpress/Function_Reference/get_children – Jignesh Patel Commented Aug 1, 2018 at 13:40
1 Answer
Reset to default 2This should work. I'm not entirely sure what is wrong with your code (it's getting late) but the below code works on my end. Obviously I replaced $order->get_id() with a known ID and post_type was set to page.
<?php
$parentid = $order->get_id();
$child = new WP_Query( array('post_parent' => $parentid, 'post_type' => 'shop_subscription') );
if ($child->have_posts()) : while ($child->have_posts()) : $child->the_post();
$childid = get_the_ID();
endwhile;
else:
$childid = "not set";
endif;
wp_reset_query();
?>
本文标签: wp queryGet Child Page IDs by Parent ID
版权声明:本文标题:wp query - Get Child Page IDs by Parent ID 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749064939a2310668.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论