<?php
defined('ABSPATH') or die('No Script "Cutties" ;) ');
if(!class_exists('adomasalcore3_wp_addons')){	
	class adomasalcore3_wp_addons{
		function __construct(){
			add_filter('terms_clauses', array($this,'get_terms_by_post_type_clause'), 99999, 3);
		}
		/*Adiciona a posibilidade de poder-se escolher o Post type na função "get_terms()"*/
		function get_terms_by_post_type_clause( $clauses, $taxonomy, $args ) {
			global $wpdb;
			if ( isset($args['post_types']) || isset($args['post_type'])) {
				if(isset($args['post_types']))
				{
					$post_types = $args['post_types'];
					// allow for arrays
					if ( is_array($args['post_types']) ) {
						$post_types = implode("','", $args['post_types']);
					}
				}
				elseif(isset($args['post_type']))
				{
					$post_types = $args['post_type'];
					// allow for arrays
					if ( is_array($args['post_type']) ) {
						$post_types = implode("','", $args['post_type']);
					}
				}
				$clauses['join'] .= " INNER JOIN $wpdb->term_relationships AS r ON r.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN $wpdb->posts AS p ON p.ID = r.object_id";
				$clauses['where'] .= " AND p.post_type IN ('". esc_sql( $post_types ). "') GROUP BY t.term_id";
			}
			return $clauses;
		}
		function get_post_content_by_id($id){
			$my_postid = $id;//This is page id or post id
			$content_post = get_post($my_postid);
			$content = $content_post->post_content;
			$content = apply_filters('the_content', $content);
			$content = str_replace(']]>', ']]&gt;', $content);
			echo $content;
		}
	}
	
	/***********************************************************************************************************/
	global $ac3;
	if($ac3===null){
		if(!is_object($ac3))
		{
			$ac3=(object) array('addons'=>new adomasalcore3_wp_addons());
		}
		else{
			$ac3->addons=new adomasalcore3_wp_addons();
		}
		function get_post_content_by_id($id){
			ob_start();
			$ac3->addons->get_post_content_by_id($id);
			return ob_get_clean();
		}
	}
}