1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
global $woo_options;
$post_types_to_loop_through = array();
$posts_to_exclude = array();
$categories_panel_entries = $woo_options['woo_categories_panel_entries'];
$more_listings_setting = $woo_options['woo_more_listings_area'];
$wp_custom_post_types_args = array();
$i = 0; // initialise incrementing variable
$wp_custom_post_types = get_post_types($wp_custom_post_types_args,'objects');
foreach ($wp_custom_post_types as $post_type_item) {
	$cpt_test = get_option('woo_categories_panel_post_types_'.$post_type_item->name);
	if ($cpt_test == 'true') {
		$cpt_nice_name = $post_type_item->labels->name;
		$cpt_has_archive = $post_type_item->has_archive;
		$post_types_to_loop_through[$post_type_item->name] = array('nice_name' => $cpt_nice_name, 'has_archive' => $cpt_has_archive);
	}
}

$section_counter = 0;

foreach ($post_types_to_loop_through as $post_type_item => $post_type_item_nice_name) {
//	$taxonomies = get_object_taxonomies($post_type_item); [this is the original line but i added line below to list location only]
	$taxonomies = array('location');
	$block_counter = 0;
	$args = array('orderby' => 'name', 'order' => 'ASC');
	?>

	<div id="location">
		
		<?php 
		// NEW AND IMPROVED QUERY
		$all_terms = get_terms( $taxonomies, $args );
		
		$block_counter = 0;
		foreach ( $all_terms as $all_term) {
			
			$tax_test = get_option('woo_categories_panel_taxonomies_'.$all_term->taxonomy);
			
			if ( ($tax_test == 'true') && ($block_counter < $categories_panel_entries) ) {
			
				$post_images = array();
				$posts_aray = array();
				
				$term_name = $all_term->name;
				$term_slug = $all_term->slug;
				$term_id = $all_term->term_id;
				$term_link = get_term_link( $all_term, $all_term->taxonomy );
				$counter_value = $all_term->count;
				?>
				
				<!--Adding foreach statement and incrementing class to the DIV-->
				<?php foreach ( $all_terms as $all_term) { ?>
				<div class="block post<?php echo $i; ?>">
				    <a href="<?php echo $term_link; ?>">
				    <?php
				    	$block_counter++;
				    	
				    	
				    	
				    	if ( $post_id > 0 ) {
				    	
				    		// If a featured image is available, use it in priority over the "image" field.
				    		if ( function_exists( 'has_post_thumbnail' ) && current_theme_supports( 'post-thumbnails' ) ) {
				    		
				    			if ( has_post_thumbnail( $post_id ) ) {
				    			
				    				$_id = 0;
				    				$_id = get_post_thumbnail_id( $post_id );
				    				
				    				if ( intval( $_id ) ) {
				    				
				    					$_image = array();
				    					$_image = wp_get_attachment_image_src( $_id, 'full' );
				    					
				    					// $_image should have 3 indexes: url, width and height.
				    					if ( count( $_image ) ) {
				    					
				    						$_image_url = $_image[0];
				    						
				    						woo_image('src=' . $_image_url . '&key=image&width=139&height=81&link=img');
				    					
				    					} // End IF Statement
				    				
				    				} // End IF Statement
				    			
				    			} else {
				    			
				    				woo_image('id='.$post_id.'&key=image&width=139&height=81&link=img');
				    				
				    			} // End IF Statement
				    		
				    		} else {
				    		
				    			woo_image('id='.$post_id.'&key=image&width=139&height=81&link=img');
				    		
				    		} // End IF Statement
				    	
				    	} else {
				    		// Fallback
				    		woo_taxonomy_image($post_images,$term_link);
				    		
				    	} // End IF Statement
				    	$php_formatting = "m\/d\/Y";
		        		$post_item_date = strtotime($post_date_raw);
				    ?>
				    	</a>
				    	
        		    <h2><a href="<?php echo $term_link; ?>"><?php echo $term_name ?> <br/><span>(<?php echo $counter_value; ?> Farmers)</span></a></h2>
        		    <p><?php _e('Latest listing ', 'woothemes') ?><?php echo date($php_formatting,$post_item_date); ?></p>
        		
        		<!--Incrementing the class in the DIV block-->
        		<?php $i++;
        		   
        		}?> 
        		</div><!-- /.block -->
        		
        		
        		
				<?php
        		if ( $block_counter % 5 == 0 ) {
        		?>
        		    <div class="fix"></div>
        		<?php
        	   	} // End IF Statement	
				
			} // End IF Statement
			
        	?>
			<?php
					
        			
		} // End For Loop
		
		?>
				
    	<div class="fix"></div>
		
		<?php if ( $block_counter > 0 ) { ?>
		
	
		
		
		<?php } else { ?>    
		<p class="woo-sc-box note" style="margin:20px 20px;"><?php _e('Please add some posts in order for this panel to work correctly. You must assign the post to these taxonomies for it to work.','woothemes'); ?></p>
		<?php } ?>
		
    </div><!-- /.listings -->
    
    <div class="fix"></div>
	
<?php } // End FOR Loop ?>