Multiple Query_Posts Using Foreach
-
I am getting a problem when try to run Multiple Loops using Foreach
The Original Code is
$getpost = new WP_Query('posts_per_page=-1&femalesubcats=a-name-female-celebrities'); if ($getpost->have_posts()) : while ($getpost->have_posts()) : $getpost->the_post(); $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { $all_tags[] = $tag->term_id; } } endwhile; endif; $tags_arr = array_unique($all_tags); $tags_str = implode(",", $tags_arr); $tag = wp_tag_cloud( array('smallest' => 10, 'largest' => 10, 'orderby' => 'name', 'order' => 'ASC', 'number' => 0, 'format' => 'array', 'include' => $tags_str ) ); ?> <?php foreach ($tag as $tag_item) : echo $tag_item.'<br />'; endforeach;
You can see i created a custom Taxonomy named Female Sub Categories (femalesubcats) having these terms
a-name-female-celebrities
b-name-female-celebrities
…
n-name-female-celebrities
..
z-name-female-celebritiesTotally A-Z Terms
Now, i placed all of the terms in array and use a single foreach
$termarray = array('a-name-female-celebrities', 'b-name-female-celebrities'); foreach( $termarray as $terms ) { $getpost = new WP_Query('posts_per_page=-1&femalesubcats='.$terms.''); if ($getpost->have_posts()) : while ($getpost->have_posts()) : $getpost->the_post(); $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { $all_tags[] = $tag->term_id; } } endwhile; endif; } $tags_arr = array_unique($all_tags); $tags_str = implode(",", $tags_arr); $tag = wp_tag_cloud( array('smallest' => 10, 'largest' => 10, 'orderby' => 'name', 'order' => 'ASC', 'number' => 0, 'format' => 'array', 'include' => $tags_str ) ); ?> <?php foreach ($tag as $tag_item) : echo $tag_item.'<br />'; endforeach; echo '--------------------';
All of the terms are showing on one page.. But the problem is i need to write the “Seperator Line” after ending the A.
But right now the line is showing after all the terms.. Means at the end of the page.
Is there anything iam missing?
Or is there any other easy way to do this.Waiting for Reply
- The topic ‘Multiple Query_Posts Using Foreach’ is closed to new replies.