I am trying to reorganize a PHP array (on a WordPress page). My site was coded by someone else, and I'm trying to make things better. I think they did things in a confusing way (poor use of the categories). Rather than recode the entire site, I wanted to see if someone could help me work around a fix.
So, basically, I have an array inside an array. A list of categories, and each category has specific details. I'm calling the categories, based on it's parent. I need to reorganize the list/array of categories, so they can print out in the order that I need them to.
$cat_tree = get_category_parents(wt_get_category_ID(), FALSE, ':', TRUE);
$top_cat = split(':',$cat_tree);
$parent = $top_cat[0];
$idObj = get_category_by_slug($parent);
$args = array(
'child_of' => $idObj->term_id,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0);
$counter_c=1;
$categories = get_categories( $args );
if($counter_c == 1) $counter_c = '';
foreach ($categories as $category) {
?>
<div> this is where each category array info gets printed... information goes:<br />
Name: <?=$category->cat_name ?> (<?=$category->cat_ID ?>)
</div>
<?php if($counter_c == '') $counter_c = 1; $counter_c++; } // Reset Query
wp_reset_query();
?>
On one page, $cat_tree outputs "entertainment:actors:".
$parent or $topcat[0] outputs "entertainment"
$topcat[1] outputs "actors"
When the "foreach" runs, I get an list sorted by the ID ...
- Actors (13)
- Artists (14)
- Directors (25)
- Writers (26)
- DeeJays (35)
I need to reorganize this list into a specific order. Each page is different. So I may have to reorganize a list differently for each page. I may need...
- Writers (26)
- Actors (13)
- DeeJays (35)
- Artists (14)
- Directors (25)
So, I need a way to do this. I thought that maybe I could say "if" on the "actor page", slide "Writers" to the end of the array (I know there is some way to do this), then slide Actors to the end, then DeeJays, then Artists, then Directors. Then run the foreach.
Or, if page is something else, I can slide other elements to the end of the array. That seems a bit much, but it's the only work around that I could think of. Of course, my php knowledge is limited, so any help is appreciated.