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


PHP sanitize_title_for_query函数代码示例

本文整理汇总了PHP中sanitize_title_for_query函数的典型用法代码示例。如果您正苦于以下问题:PHP sanitize_title_for_query函数的具体用法?PHP sanitize_title_for_query怎么用?PHP sanitize_title_for_query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: ap_find_mentioned_users

function ap_find_mentioned_users($content)
{
    global $wpdb;
    // Find all mentions in content.
    preg_match_all('/(?:[\\s.]|^)@(\\w+)/', $content, $matches);
    if (is_array($matches) && count($matches) > 0 && !empty($matches[0])) {
        $user_logins = array();
        // Remove duplicates.
        $unique_logins = array_unique($matches[0]);
        foreach ($unique_logins as $user_login) {
            $user_logins[] = sanitize_title_for_query(sanitize_user(wp_unslash($user_login), true));
        }
        if (count($user_logins) == 0) {
            return false;
        }
        $user_logins_s = "'" . implode("','", $user_logins) . "'";
        $key = md5($user_logins_s);
        $cache = wp_cache_get($key, 'ap_user_ids');
        if (false !== $cache) {
            return $cache;
        }
        $query = $wpdb->prepare("SELECT id, user_login FROM {$wpdb->users} WHERE user_login IN ({$user_logins_s})");
        $result = $wpdb->get_results($query);
        wp_cache_set($key, $result, 'ap_user_ids');
        return $result;
    }
    return false;
}
开发者ID:Byrlyne,项目名称:anspress,代码行数:28,代码来源:mention.php

示例2: edd_get_download_by

/**
 * Retrieve a download by a given field
 *
 * @since       2.0
 * @param       string $field The field to retrieve the discount with
 * @param       mixed $value The value for field
 * @return      mixed
 */
function edd_get_download_by($field = '', $value = '')
{
    if (empty($field) || empty($value)) {
        return false;
    }
    switch (strtolower($field)) {
        case 'id':
            $download = get_post($value);
            if (get_post_type($download) != 'download') {
                return false;
            }
            break;
        case 'slug':
        case 'name':
            $download = query_posts(array('post_type' => 'download', 'name' => sanitize_title_for_query($value), 'posts_per_page' => 1, 'post_status' => 'any'));
            if ($download) {
                $download = $download[0];
            }
            break;
        case 'sku':
            $download = query_posts(array('post_type' => 'download', 'meta_key' => 'edd_sku', 'meta_value' => $value, 'posts_per_page' => 1, 'post_status' => 'any'));
            if ($download) {
                $download = $download[0];
            }
            break;
        default:
            return false;
    }
    if ($download) {
        return $download;
    }
    return false;
}
开发者ID:Bragi26,项目名称:Easy-Digital-Downloads,代码行数:41,代码来源:download-functions.php

示例3: my_bbp_filter_search_results

function my_bbp_filter_search_results($r)
{
    //Get the submitted forum ID (from the hidden field added in step 2)
    $forum_id = isset($_GET['bbp_search_forum_id']) ? sanitize_title_for_query($_GET['bbp_search_forum_id']) : false;
    //If the forum ID exits, filter the query
    if ($forum_id && is_numeric($forum_id)) {
        $r['meta_query'] = array(array('key' => '_bbp_forum_id', 'value' => $forum_id, 'compare' => '='));
    }
    return $r;
}
开发者ID:quyip8818,项目名称:wps,代码行数:10,代码来源:config.php

示例4: sendpress_register_template

function sendpress_register_template($html_template = array())
{
    global $sendpress_html_templates;
    $id = SendPress_Data::get_html_template_id_by_slug(sanitize_title_for_query($html_template['name']));
    //$id = 0;
    echo $id;
    $content = file_get_contents($html_template['path']);
    $my_post = array('ID' => $id, 'post_content' => $content, 'post_title' => $html_template['name'], 'post_status' => 'draft');
    //print_r( $my_post );
    // Update the post into the database
    wp_update_post($my_post);
    //$html_template['ID'] = $id;
    //$sendpress_html_templates[$id] = $html_template;
}
开发者ID:richardsweeney,项目名称:sendpress,代码行数:14,代码来源:functions.php

示例5: terrific_pre_get_posts

/**
 * Redirects slugs with old separator to new permalinks.
 *
 * @param $query the query object
 * @return void
 * @since 1.0
 */
function terrific_pre_get_posts($query)
{
    global $wpdb;
    $name = $query->query_vars['name'];
    if (strpos($name, SLUG_SEPARATOR_OLD) > 0) {
        $name = sanitize_title_for_query($name);
        $new_name = str_replace(SLUG_SEPARATOR_OLD, SLUG_SEPARATOR_NEW, $name);
        $posts = $wpdb->get_results("\n            SELECT ID, post_title, post_name\n            FROM {$wpdb->posts}\n            WHERE\n                post_name = '" . $new_name . "' AND\n                post_status = 'publish' AND\n                post_type = 'post'\n            LIMIT 1\n        ");
        foreach ($posts as $post) {
            $permalink = get_permalink($post->ID);
            header('HTTP/1.1 301 Moved Permanently');
            header('Location: ' . $permalink);
            exit;
        }
        wp_reset_query();
    }
}
开发者ID:rogerdudler,项目名称:terrific-integration-wordpress,代码行数:24,代码来源:functions.php

示例6: count_comment_by_email

 static function count_comment_by_email($email, $post_id = false, $comment_type = false)
 {
     if (!$email) {
         return 0;
     }
     if ($email) {
         global $wpdb;
         $query = 'SELECT COUNT(comment_ID) FROM ' . $wpdb->comments . ' WHERE comment_author_email = "' . $email . '"';
         if ($post_id) {
             $query .= ' AND comment_post_ID="' . sanitize_title_for_query($post_id) . '"';
         }
         if ($comment_type) {
             $query .= ' AND comment_type="' . sanitize_title_for_query($comment_type) . '"';
         }
         $count = $wpdb->get_var($query);
         return $count;
     }
 }
开发者ID:DaddyFool,项目名称:travelTest,代码行数:18,代码来源:class.user.php

示例7: ap_remove_subscriber

/**
 * Remove subscriber for question or term
 * @param  integer         $item_id  	Question ID or Term ID
 * @param  integer         $user_id    	WP user ID
 * @param  string          $activity    Any sub ID
 * @param  boolean|integer $sub_id      @deprecated Type of subscriber, empty string for question
 * @return bollean|integer
 */
function ap_remove_subscriber($item_id, $user_id = false, $activity = false, $sub_id = false)
{
    if (false !== $sub_id) {
        _deprecated_argument(__FUNCTION__, '3.0', '$sub_id argument deprecated since 2.4');
    }
    global $wpdb;
    $cols = array('item_id' => (int) $item_id);
    if (false !== $user_id) {
        $cols['user_id'] = (int) $user_id;
    }
    if (false !== $activity) {
        $cols['activity'] = sanitize_title_for_query($activity);
    }
    $row = $wpdb->delete($wpdb->ap_subscribers, $cols, array('%d', '%d', '%s'));
    if (false === $row) {
        return false;
    }
    do_action('ap_removed_subscriber', $user_id, $item_id, $activity);
    return $row;
}
开发者ID:Krl4,项目名称:anspress,代码行数:28,代码来源:subscriber.php

示例8: serach_qa_by_userid

 /**
  * Add author args in query
  * @param  object $query WP_Query object.
  */
 public function serach_qa_by_userid($query)
 {
     $screen = get_current_screen();
     if (isset($query->query_vars['s'], $screen->id, $screen->post_type) && ($screen->id == 'edit-question' && $screen->post_type == 'question' || $screen->id == 'edit-answer' && $screen->post_type == 'answer') && $query->is_main_query()) {
         $search_q = ap_parse_search_string(get_search_query());
         // Set author args.
         if (!empty($search_q['author_id']) && is_array($search_q['author_id'])) {
             $user_ids = '';
             foreach ($search_q['author_id'] as $id) {
                 $user_ids .= (int) $id . ',';
             }
             set_query_var('author', rtrim($user_ids, ','));
         } elseif (!empty($search_q['author_name']) && is_array($search_q['author_name'])) {
             $author_names = array();
             foreach ($search_q['author_name'] as $id) {
                 $author_names[] = sanitize_title_for_query($id);
             }
             set_query_var('ap_author_name', $author_names);
         }
         set_query_var('s', $search_q['q']);
     }
 }
开发者ID:deepakd92,项目名称:anspress,代码行数:26,代码来源:anspress-admin.php

示例9: get_posts


//.........这里部分代码省略.........
     if (!empty($q['date_query'])) {
         $this->date_query = new ES_WP_Date_Query($q['date_query']);
         $date_filter = $this->date_query->get_dsl($this);
         if (!empty($date_filter)) {
             $filter[] = $date_filter;
         } elseif (false === $date_filter) {
             // @todo: potentially do this differently; see no_results() for more info
             return $this->no_results();
         }
         unset($date_filter);
     }
     // If we've got a post_type AND it's not "any" post_type.
     if (!empty($q['post_type']) && 'any' != $q['post_type']) {
         foreach ((array) $q['post_type'] as $_post_type) {
             $ptype_obj = get_post_type_object($_post_type);
             if (!$ptype_obj || !$ptype_obj->query_var || empty($q[$ptype_obj->query_var])) {
                 continue;
             }
             if (!$ptype_obj->hierarchical || strpos($q[$ptype_obj->query_var], '/') === false) {
                 // Non-hierarchical post_types & parent-level-hierarchical post_types can directly use 'name'
                 $q['name'] = $q[$ptype_obj->query_var];
             } else {
                 // Hierarchical post_types will operate through the
                 $q['pagename'] = $q[$ptype_obj->query_var];
                 $q['name'] = '';
             }
             // Only one request for a slug is possible, this is why name & pagename are overwritten above.
             break;
         }
         //end foreach
         unset($ptype_obj);
     }
     if ('' != $q['name']) {
         $q['name'] = sanitize_title_for_query($q['name']);
         $filter[] = $this->dsl_terms($this->es_map('post_name'), $q['name']);
     } elseif ('' != $q['pagename']) {
         if (isset($this->queried_object_id)) {
             $reqpage = $this->queried_object_id;
         } else {
             if ('page' != $q['post_type']) {
                 foreach ((array) $q['post_type'] as $_post_type) {
                     $ptype_obj = get_post_type_object($_post_type);
                     if (!$ptype_obj || !$ptype_obj->hierarchical) {
                         continue;
                     }
                     $reqpage = get_page_by_path($q['pagename'], OBJECT, $_post_type);
                     if ($reqpage) {
                         break;
                     }
                 }
                 unset($ptype_obj);
             } else {
                 $reqpage = get_page_by_path($q['pagename']);
             }
             if (!empty($reqpage)) {
                 $reqpage = $reqpage->ID;
             } else {
                 $reqpage = 0;
             }
         }
         $page_for_posts = get_option('page_for_posts');
         if ('page' != get_option('show_on_front') || empty($page_for_posts) || $reqpage != $page_for_posts) {
             $q['pagename'] = sanitize_title_for_query(wp_basename($q['pagename']));
             $q['name'] = $q['pagename'];
             $filter[] = $this->dsl_terms($this->es_map('post_id'), absint($reqpage));
             $reqpage_obj = get_post($reqpage);
开发者ID:GiantRobX,项目名称:wordpress-vip-plugins,代码行数:67,代码来源:class-es-wp-query-wrapper.php

示例10: getPostID

 public function getPostID($Class)
 {
     $db = $this->wpdb;
     $post_type = sanitize_title_for_query($Class::POST_TYPE);
     return $this->query("SELECT ID FROM {$db->posts} WHERE post_type = '{$post_type}' AND post_status = 'publish' ");
 }
开发者ID:konstantin-mohin,项目名称:WordPress,代码行数:6,代码来源:DatabaseAccessWrapper.php

示例11: _alter_search_query

 static function _alter_search_query($where)
 {
     global $wp_query;
     if (!is_admin()) {
         return $where;
     }
     if ($wp_query->get('post_type') != 'hotel_room') {
         return $where;
     }
     global $wpdb;
     if ($wp_query->get('s')) {
         $_GET['s'] = isset($_GET['s']) ? sanitize_title_for_query($_GET['s']) : '';
         $add_where = " OR {$wpdb->posts}.ID IN (SELECT post_id FROM\r\n                     {$wpdb->postmeta}\r\n                    WHERE {$wpdb->postmeta}.meta_key ='room_parent'\r\n                    AND {$wpdb->postmeta}.meta_value IN (SELECT {$wpdb->posts}.ID\r\n                        FROM {$wpdb->posts} WHERE  {$wpdb->posts}.post_title LIKE '%{$_GET['s']}%'\r\n                    )\r\n\r\n             )  ";
         $where .= $add_where;
     }
     return $where;
 }
开发者ID:DaddyFool,项目名称:travelTest,代码行数:17,代码来源:class.admin.room.php

示例12: get_option

        $output .= "</div>";
        $output .= "</div><hr>";
    }
    if ($news->post_count != 0) {
        $landingpage = get_option('options_module_events_page');
        if (!$landingpage) {
            $landingpage_link_text = 'events';
            $landingpage = site_url() . '/events/';
        } else {
            $landingpage_link_text = get_the_title($landingpage[0]);
            $landingpage = get_permalink($landingpage[0]);
        }
        $output .= '<p class="events-more"><strong><a title="' . $landingpage_link_text . '" class="small" href="' . $landingpage . '">' . $landingpage_link_text . '</a></strong> <span class="dashicons dashicons-arrow-right-alt2"></span></p>';
        $output .= $after_widget;
    }
    $output .= "</div>";
    $output .= "</div>";
    set_transient('aggregator_events_' . $colid . '_' . sanitize_title_for_query($title), $output, 5 * 60);
    // set cache period 5 minutes
}
if ($output) {
    echo "<div class='widget-box'>";
    if ($title) {
        echo "<h3>" . esc_attr($title) . "</h3>";
    }
    echo $output;
    echo "</div>";
}
wp_reset_postdata();
?>
			
开发者ID:openterengganu,项目名称:govintranet,代码行数:30,代码来源:part-event-listing.php

示例13: find_post_id_by_slug

 /**
  * Find the post ID by given post_name. the slug is sanitized the same way as WP_Query. 
  * see this link for more info. https://developer.wordpress.org/reference/functions/sanitize_title_for_query/
  * This function should be slightly faster than get_posts, get_pages or WP_Query as those general purpose functions fetch whole bunch of information not really needed.
  * It does not require joining meta table either.
  * @param string $slug, post_name of the post. Note this is not the post_title. It is the name (slug) normally appearing in the url if permalink is enabled.
  * @return number. the post id, of the post_type _pods_pod. 
  * @since 1.0
  */
 static function find_post_id_by_slug($slug)
 {
     $slug = sanitize_title_for_query($slug);
     global $wpdb;
     $table_prefix = $wpdb->get_blog_prefix();
     $post_id = $wpdb->get_var("\n\t\t\t\t\tSELECT  ID \n\t\t\t\t\tFROM " . $table_prefix . "posts\n\t\t\t\t\tWHERE post_name='" . $slug . "' \n\t\t\t\t\tAND post_type='_pods_pod'\n\t\t\t\t\n\t\t\t\t\t");
     if ($post_id) {
         return $post_id;
     } else {
         return false;
     }
 }
开发者ID:visualdatasolutions,项目名称:custom-field-groups-for-pods,代码行数:21,代码来源:custom-field-groups-for-pods.php

示例14: do_action_ref_array


//.........这里部分代码省略.........
         $where .= " AND SECOND({$wpdb->posts}.post_date)='" . $q['second'] . "'";
     }
     if ($q['year']) {
         $where .= " AND YEAR({$wpdb->posts}.post_date)='" . $q['year'] . "'";
     }
     if ($q['monthnum']) {
         $where .= " AND MONTH({$wpdb->posts}.post_date)='" . $q['monthnum'] . "'";
     }
     if ($q['day']) {
         $where .= " AND DAYOFMONTH({$wpdb->posts}.post_date)='" . $q['day'] . "'";
     }
     // If we've got a post_type AND its not "any" post_type.
     if (!empty($q['post_type']) && 'any' != $q['post_type']) {
         foreach ((array) $q['post_type'] as $_post_type) {
             $ptype_obj = get_post_type_object($_post_type);
             if (!$ptype_obj || !$ptype_obj->query_var || empty($q[$ptype_obj->query_var])) {
                 continue;
             }
             if (!$ptype_obj->hierarchical || strpos($q[$ptype_obj->query_var], '/') === false) {
                 // Non-hierarchical post_types & parent-level-hierarchical post_types can directly use 'name'
                 $q['name'] = $q[$ptype_obj->query_var];
             } else {
                 // Hierarchical post_types will operate through the
                 $q['pagename'] = $q[$ptype_obj->query_var];
                 $q['name'] = '';
             }
             // Only one request for a slug is possible, this is why name & pagename are overwritten above.
             break;
         }
         //end foreach
         unset($ptype_obj);
     }
     if ('' != $q['name']) {
         $q['name'] = sanitize_title_for_query($q['name']);
         $where .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'";
     } elseif ('' != $q['pagename']) {
         if (isset($this->queried_object_id)) {
             $reqpage = $this->queried_object_id;
         } else {
             if ('page' != $q['post_type']) {
                 foreach ((array) $q['post_type'] as $_post_type) {
                     $ptype_obj = get_post_type_object($_post_type);
                     if (!$ptype_obj || !$ptype_obj->hierarchical) {
                         continue;
                     }
                     $reqpage = get_page_by_path($q['pagename'], OBJECT, $_post_type);
                     if ($reqpage) {
                         break;
                     }
                 }
                 unset($ptype_obj);
             } else {
                 $reqpage = get_page_by_path($q['pagename']);
             }
             if (!empty($reqpage)) {
                 $reqpage = $reqpage->ID;
             } else {
                 $reqpage = 0;
             }
         }
         $page_for_posts = get_option('page_for_posts');
         if ('page' != get_option('show_on_front') || empty($page_for_posts) || $reqpage != $page_for_posts) {
             $q['pagename'] = sanitize_title_for_query(wp_basename($q['pagename']));
             $q['name'] = $q['pagename'];
             $where .= " AND ({$wpdb->posts}.ID = '{$reqpage}')";
             $reqpage_obj = get_page($reqpage);
开发者ID:nunomorgadinho,项目名称:WordPress,代码行数:67,代码来源:query.php

示例15: get_posts


//.........这里部分代码省略.........
     }
     unset($date_parameters, $date_query);
     // Handle complex date queries
     if (!empty($q['date_query'])) {
         $this->date_query = new WP_Date_Query($q['date_query']);
         $where .= $this->date_query->get_sql();
     }
     // If we've got a post_type AND it's not "any" post_type.
     if (!empty($q['post_type']) && 'any' != $q['post_type']) {
         foreach ((array) $q['post_type'] as $_post_type) {
             $ptype_obj = get_post_type_object($_post_type);
             if (!$ptype_obj || !$ptype_obj->query_var || empty($q[$ptype_obj->query_var])) {
                 continue;
             }
             if (!$ptype_obj->hierarchical) {
                 // Non-hierarchical post types can directly use 'name'.
                 $q['name'] = $q[$ptype_obj->query_var];
             } else {
                 // Hierarchical post types will operate through 'pagename'.
                 $q['pagename'] = $q[$ptype_obj->query_var];
                 $q['name'] = '';
             }
             // Only one request for a slug is possible, this is why name & pagename are overwritten above.
             break;
         }
         //end foreach
         unset($ptype_obj);
     }
     if ('' !== $q['title']) {
         $where .= $this->db->prepare(" AND {$this->db->posts}.post_title = %s", stripslashes($q['title']));
     }
     // Parameters related to 'post_name'.
     if ('' != $q['name']) {
         $q['name'] = sanitize_title_for_query($q['name']);
         $where .= " AND {$this->db->posts}.post_name = '" . $q['name'] . "'";
     } elseif ('' != $q['pagename']) {
         if (isset($this->queried_object_id)) {
             $reqpage = $this->queried_object_id;
         } else {
             if ('page' != $q['post_type']) {
                 foreach ((array) $q['post_type'] as $_post_type) {
                     $ptype_obj = get_post_type_object($_post_type);
                     if (!$ptype_obj || !$ptype_obj->hierarchical) {
                         continue;
                     }
                     $reqpage = get_page_by_path($q['pagename'], OBJECT, $_post_type);
                     if ($reqpage) {
                         break;
                     }
                 }
                 unset($ptype_obj);
             } else {
                 $reqpage = get_page_by_path($q['pagename']);
             }
             if (!empty($reqpage)) {
                 $reqpage = $reqpage->ID;
             } else {
                 $reqpage = 0;
             }
         }
         $page_for_posts = get_option('page_for_posts');
         if ('page' != get_option('show_on_front') || empty($page_for_posts) || $reqpage != $page_for_posts) {
             $q['pagename'] = sanitize_title_for_query(wp_basename($q['pagename']));
             $q['name'] = $q['pagename'];
             $where .= " AND ({$this->db->posts}.ID = '{$reqpage}')";
             $reqpage_obj = get_post($reqpage);
开发者ID:inpsyde,项目名称:wordpress-dev,代码行数:67,代码来源:class-wp-query.php


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