how do I get a specific post from a post with a subcategory in WP

Question

I’m trying to do a project in WP that has subcategories that belong to certain categories and those subcategories have N posts.

In a certain area of ​​the project I have to play some specific posts are about 5 posts that were on the home I tried to use:

$cats = get_categories();
$catParent = array();
foreach ($cats as $cat){
  if($cat-category_parent ==0){
    array_push($catParent, $cat);
  }
}
foreach ($catParent as $cp) {
   $cp_link = get_category_link($cp->term_id);
   $catChild = get_categories(array('parent' => $cp->cat_ID));

   if (!empty($catschild)) {
      foreach ($catschild as $ch) {
         $posts = get_post(array('cat' => $ch->term_id));
         $chLink = get_category_link($cp->term_id);
      }
   }
}

until then I can get the posts kinda bugged by the 20 posts only return 16 kkkkk if you can help me I would be forever grateful
and this code takes all and returns in array but I still can’t get a specific post

0
Renan Marques 2 months 0 Answers 14 views 0

Leave an answer