• Resolved tnoguchi

    (@tnoguchi)


    Hi,

    I’m developing a custom category page template that’s trying to merge two arrays retrieved by get_categories with the array_merge function.

    While it’s retrieving the results, and I’m able to output the category data in a foreach loop. For some reason, the categories are being outputted in a seemingly unpredictable order; neither in an ascending or descending order as defined in my arguments. Can anyone point me to where I’m going wrong here?

    Basically, I would like to retrieve posts from two categories and their children in a specified ascending order. Any advice would be greatly appreciated.

    <?php 	function portfolio_browser(){    
    
    			global $cat;
    
    $arg1 = array(
    'type' => 'post',
    'child_of' => 36,
    'order' => 'DESC',
    'order_by' => 'cat_ID',
    'hide_empty' => false,
    'hierarchical' => true
     );
    
    $arg2 = array(
    'type'=> 'post',
    'child_of'=> 23,
    'order_by' => 'cat_ID',
    'order'=> 'DESC',
    'hide_empty' => false,
    'hierarchical'=> true,
    'exclude' => array(27, 28, 29, 31, 32)
     );
    
     $projectcats = get_categories($arg1);
     $teachingcats = get_categories($arg2);
     $combinedcats = array_merge($projectcats,$teachingcats);				 ?>
    
    <?php foreach ($combinedcats as $combinedcat): 											           $slug = $combinedcat->slug;
     $cat = $combinedcat->term_id;?>
    																		<?php if ($cat == '33') { ?>
    
    										<section id="teaching">
    												<h1>Teaching</h1>
    												<div class="content-item text">
    
    														<?php 	$key="Teaching Text";
    																$key2="Teaching Image"; ?>
    
    														<img src="<?php echo get_post_meta($post->ID, $key2, true);?>" alt="Teaching Section Header Image"> 
    
    														<p><?php echo get_post_meta($post->ID, $key, true); ?></p>
    
    												</div>
    
    										</section><!--#teaching-->
    
    									<?php } ?>	            	
    
    <section id="<?php echo $slug ?>" class="content-item">
    
    	<?php bigwitz_portfolio_view(); ?>
    
    </section><!--<?php echo $slug ?>-->
    			<?php  endforeach;  
    
    		} ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Combining Category Arrays with array_merge’ is closed to new replies.