[英]Return child of page in wordpress search
I'm making a search (wordpress) that should return only the child of a page.我正在进行搜索 (wordpress),应该只返回页面的子页面。 It is currently returning all pages.
它当前正在返回所有页面。 I need it to return only the children of a page in the results.
我需要它在结果中只返回页面的子级。
The parent page is 'products' so the url is like this:父页面是“产品”,所以 url 是这样的:
www.helpme.com/products/child-page-1 www.helpme.com/products/child-page-1
www.helpme.com/products/child-page-2 www.helpme.com/products/child-page-2
My code:我的代码:
if(have_posts()){
while(have_posts()){
the_post();
if ( $post->post_parent == 'products' ){
something
}
}
}
?>
can you help me, please ?
Try this:尝试这个:
$products_page = get_page_by_path( 'products' );
if(have_posts()){
while(have_posts()){
the_post();
if ( $post->post_parent == $products_page->ID ){
something
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.