当前位置: 首页>>代码示例>>PHP>>正文


PHP EM_Object::context方法代码示例

本文整理汇总了PHP中EM_Object::context方法的典型用法代码示例。如果您正苦于以下问题:PHP EM_Object::context方法的具体用法?PHP EM_Object::context怎么用?PHP EM_Object::context使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EM_Object的用法示例。


在下文中一共展示了EM_Object::context方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array


//.........这里部分代码省略.........
     }
     //START TAXONOMY FILTERS - can be id, slug, name or comma seperated ids/slugs/names, if negative or prepended with a - then considered a negative filter
     $taxonomies = self::get_taxonomies();
     foreach ($taxonomies as $tax_name => $tax_data) {
         if (!empty($args[$tax_name]) && is_array($args[$tax_name])) {
             if (!empty($tax_data['ms'])) {
                 self::ms_global_switch();
             }
             //if in ms global mode, switch here rather than on each EM_Category instance
             //build array of term ids and negative ids from supplied argument
             $term_tax_ids = $term_ids = array();
             $term_tax_not_ids = $term_not_ids = array();
             foreach ($args[$tax_name] as $tax_id) {
                 $tax_id_clean = preg_replace('/^-/', '', $tax_id);
                 if (!is_numeric($tax_id_clean)) {
                     $term = get_term_by('slug', $tax_id_clean, $tax_data['name']);
                     if (empty($term)) {
                         $term = get_term_by('name', $tax_id_clean, $tax_data['name']);
                     }
                 } else {
                     $term = get_term_by('id', $tax_id_clean, $tax_data['name']);
                 }
                 if (!empty($term->term_taxonomy_id)) {
                     if (!preg_match('/^-/', $tax_id)) {
                         $term_tax_ids[] = $term->term_taxonomy_id;
                         if (EM_MS_GLOBAL && !empty($tax_data['ms'])) {
                             $term_ids[] = $term->term_id;
                         }
                     } else {
                         $term_tax_not_ids[] = $term->term_taxonomy_id;
                         if (EM_MS_GLOBAL && !empty($tax_data['ms'])) {
                             $term_not_ids[] = $term->term_id;
                         }
                     }
                 }
             }
             if (!empty($tax_data['ms'])) {
                 self::ms_global_switch_back();
             }
             //switch back if ms global mode
             //create sql conditions
             if (count($term_tax_ids) > 0 || count($term_tax_not_ids) > 0) {
                 //figure out context - what table/field to search
                 $post_context = EM_EVENTS_TABLE . ".post_id";
                 $ms_context = EM_EVENTS_TABLE . ".event_id";
                 if (!empty($tax_data['context']) && self::$context == EM_POST_TYPE_LOCATION && in_array(self::$context, $tax_data['context'])) {
                     //context can be either locations or events, since those are the only two CPTs we deal with
                     $post_context = EM_LOCATIONS_TABLE . ".post_id";
                     $ms_context = EM_LOCATIONS_TABLE . ".event_id";
                 }
                 //build conditions
                 $tax_conds = array();
                 if (EM_MS_GLOBAL && !empty($tax_data['ms'])) {
                     //by default only applies to categories
                     //we're directly looking for tax ids from within the em_meta table
                     if (count($term_ids) > 0) {
                         $tax_conds[] = "{$ms_context} IN ( SELECT object_id FROM " . EM_META_TABLE . " WHERE meta_value IN (" . implode(',', $term_ids) . ") AND meta_key='{$tax_data['ms']}' )";
                     }
                     if (count($term_not_ids) > 0) {
                         $tax_conds[] = "{$ms_context} NOT IN ( SELECT object_id FROM " . EM_META_TABLE . " WHERE meta_value IN (" . implode(',', $term_not_ids) . ") AND meta_key='{$tax_data['ms']}' )";
                     }
                 } else {
                     //normal taxonomy filtering
                     if (count($term_tax_ids) > 0) {
                         $tax_conds[] = "{$post_context} IN ( SELECT object_id FROM " . $wpdb->term_relationships . " WHERE term_taxonomy_id IN (" . implode(',', $term_tax_ids) . ") )";
                     }
                     if (count($term_tax_not_ids) > 0) {
                         $tax_conds[] = "{$post_context} NOT IN ( SELECT object_id FROM " . $wpdb->term_relationships . " WHERE term_taxonomy_id IN (" . implode(',', $term_tax_not_ids) . ") )";
                     }
                 }
                 if (count($tax_conds) > 0) {
                     $conditions[$tax_name] = '(' . implode(' AND ', $tax_conds) . ')';
                 }
             } else {
                 $conditions = array('taxonomy' => '2=1');
                 //force a false, supplied taxonomies don't exist
                 break;
                 //no point continuing this loop
             }
         }
     }
     //END TAXONOMY FILTERS
     //If we want rsvped items, we usually check the event
     if ($bookings == 1) {
         $conditions['bookings'] = 'event_rsvp=1';
     }
     //Default ownership belongs to an event, child objects can just overwrite this if needed.
     if (is_numeric($owner)) {
         $conditions['owner'] = 'event_owner=' . $owner;
     } elseif ($owner == 'me' && is_user_logged_in()) {
         $conditions['owner'] = 'event_owner=' . get_current_user_id();
     } elseif ($owner == 'me' && !is_user_logged_in()) {
         $conditions = array('owner' => '1=2');
         //no events to be shown
     }
     //reset the context
     self::$context = EM_POST_TYPE_EVENT;
     //return values
     return apply_filters('em_object_build_sql_conditions', $conditions);
 }
开发者ID:pyropictures,项目名称:wordpress-plugins,代码行数:101,代码来源:em-object.php


注:本文中的EM_Object::context方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。