{
        if (!class_exists('Network_Query')) {
            return array();
        }
        $query = new Network_Query();
        return $query->query(array('tax_query' => array(array('taxonomy' => 'post_tag', 'field' => 'slug', 'terms' => $tags))));
    }
    public static function get_post_blog_id($post)
    {
        if (self::has_old_post_indexer() && !empty($post['blog_id'])) {
            return $post['blog_id'];
        }
        if (self::has_new_post_indexer() && !empty($post->BLOG_ID)) {
            return $post->BLOG_ID;
        }
        return 0;
    }
    public static function get_post_post_id($post)
    {
        if (self::has_old_post_indexer() && !empty($post['post_id'])) {
            return (int) $post['post_id'];
        }
        if (self::has_new_post_indexer() && !empty($post->ID)) {
            return (int) $post->ID;
        }
        return 0;
    }
}
// Post Indexer (http://premium.wpmudev.org/project/post-indexer) integration
define('AGM_USE_POST_INDEXER', Agm_PostIndexer::has_post_indexer(), true);
Exemplo n.º 2
0
 /**
  * Fetches network maps associated with posts found with custom WP posts query.
  * Requires Post Indexer plugin.
  *
  * @param string Custom WP posts query
  * @return mixed Maps array on success, false on failure
  */
 function get_custom_network_maps($query)
 {
     if (!AGM_USE_POST_INDEXER) {
         return false;
     }
     $tags = explode('tag=', $query);
     if (!isset($tags[1])) {
         return false;
     }
     $tags = explode(',', $tags[1]);
     $posts = Agm_PostIndexer::get_posts_by_tags($tags);
     if (empty($posts)) {
         return false;
     }
     $sql = array();
     foreach ($posts as $post) {
         $blog_id = Agm_PostIndexer::get_post_blog_id($post);
         $post_id = Agm_PostIndexer::get_post_post_id($post);
         switch_to_blog($blog_id);
         $len = strlen($post_id);
         $table = $this->get_table_name();
         $sql[] = "SELECT *, {$blog_id} as blog_id FROM {$table} WHERE {$table}.post_ids LIKE '%s:{$len}:\"{$post_id}\";%'";
         restore_current_blog();
     }
     $sql = join(' UNION ', $sql);
     $maps = $this->wpdb->get_results($sql, ARRAY_A);
     if (is_array($maps)) {
         foreach ($maps as $k => $v) {
             $maps[$k] = $this->prepare_map($v);
         }
     }
     return $maps;
 }