0

I'm trying to show a category and his children with this structure (whit this content()):

 - Category Father title
     - Children title
     - Other children title
 - Category Father title
     - ....

But with this code

$catH = array(11);
$query = array("cat"=>42,"order"=>"ASC","posts_per_page"=>-1,"category__not_in"=>$catH);
$obj = new WP_Query($query);
if ($obj->have_posts()){    
    while($obj->have_posts()){
        $obj->the_post();
        $slug = get_the_tags();         
        the_title();
        echo "<br/>";
        $queryH = array("cat"=>13,"order"=>"ASC","posts_per_page"=>-1,"tag__in"=>$slug);
        $objH = new WP_Query($queryH);
        if ($objH->have_posts()){
            while($objH->have_posts()){
                $objH->the_post();
                the_title();
                echo "<br/>";
            }
        }
    }
    wp_reset_postdata();    
}

The result is like that:

  • Category Father title
  • Category Father title

  • Children title

  • Other children title

How can I fixed it?

0

try like this:

if ($obj->have_posts()){    
    while($obj->have_posts()){
        $obj->the_post();
        $slug = get_the_tags();         
        $obj->the_title();
        echo "<br/>";
        $queryH = array("cat"=>13,"order"=>"ASC","posts_per_page"=>-1,"tag__in"=>$slug);
        $objH = new WP_Query($queryH);
        if ($objH->have_posts()){
            while($objH->have_posts()){
                $objH->the_post();
                $objH->the_title();
                echo "<br/>";
            }
        }
    }  
}
  • I've try and the result is similiar to what I need. Thanks! – Marcos Jan 3 '17 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.