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
#place this code on top of functions.php, before the framework is loaded


if(!function_exists('avia_get_meta'))
{
	function avia_post_meta($post_id = '', $subkey = false)
	{
		//if the user only passed a string and no id the string will be used as subkey
		if(!$subkey && $post_id != "" && !is_numeric($post_id) && !is_object($post_id))
		{
			$subkey = $post_id;
			$post_id = "";
		}
		
		global $avia, $avia_config;
		$key = '_avia_elements_'.$avia->option_prefix;
		$values = "";
		
		//if post id is on object the function was called via hook. If thats the case reset the meta array
		if(is_object($post_id) && isset($post_id->ID)) 
		{ 
			unset($avia_config['meta']);
			$post_id = $post_id->ID;
		}
		
		if(!$post_id) 
		{ 
			$post_id = get_the_ID();
		}
		
		if(!is_numeric($post_id)) return;
		
		
		if(!isset($avia_config['meta']))
		{	
			$avia_config['meta'] = avia_deep_decode(get_post_meta($post_id, $key, true));
		}
	
		
		if($subkey && isset($avia_config['meta'][$subkey]))
		{
			$meta = $avia_config['meta'][$subkey];
			
			if($subkey == 'slideshow')
			{
				if(empty($meta[0]['slideshow_image']))
				{
					$post_thumb_id = get_post_thumbnail_id($post_id); 
				
					if(is_numeric($post_thumb_id))
					{
						$meta[0]['slideshow_image'] = $post_thumb_id;
					}
				}
			}
			
		}
		else
		{
			$meta = false;
		}
		
		return $meta;
	}
	
	add_action('the_post', 'avia_post_meta');
	add_theme_support( 'post-thumbnails' );
	function avia_get_meta(){}
}