admin管理员组

文章数量:1316304

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

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

Share Improve this question edited Nov 10, 2020 at 1:53 Tom J Nowell 61k7 gold badges79 silver badges148 bronze badges asked Nov 10, 2020 at 1:12 Renan MarquesRenan Marques 111 bronze badge 3
  • Can you edit your question to rewrite the sentence before your code block? I've read it a few times and I do not understand what the sentence is trying to say, the phrase "the home I tried to use" what is home referring to?. Also, please indent your code block correctly. – Tom J Nowell Commented Nov 10, 2020 at 1:51
  • sorry man : 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 that I have to show some specific posts are about 5 posts that were in the begin of the page. code that I tried to use: – Renan Marques Commented Nov 10, 2020 at 3:28
  • What is this certain area and where is this code running? How does it relate to these categories and the other posts? Can you make this question less generic/abstract? Context with examples would help enormously, it's currently too generic/abstract to understand. E.g. how do we know which sub-category? And which specific posts? Are you just asking how to list posts in a named subcategory? – Tom J Nowell Commented Nov 10, 2020 at 12:32
Add a comment  | 

1 Answer 1

Reset to default 0

all of this code is running on the index. php. example: category 1 has 5 subcategories; the subcategory 2 of category 1 has 8 posts and two of these posts have three tags, that will be used in my code as an identifier for the initial page within a wall of 5 posts to display these posts from the aforementioned subcategory and another 2 posts from another specific sub category

本文标签: phphow do I get a specific post from a post with a subcategory in WP