Home > Software engineering >  Return child of page in wordpress search
Return child of page in wordpress search

Time:01-13

I'm making a search (wordpress) that should return only the child of a page. 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:

www.helpme.com/products/child-page-1

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 ?

CodePudding user response:

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
        }
    }
}
  • Related