コード例 #1
0
ファイル: post.php プロジェクト: skylarkcob/hocwp-projects
function hocwp_insert_trending($args = array())
{
    if (!is_array($args) && is_numeric($args)) {
        $args = array('post_id' => $args);
    }
    $post_id = hocwp_get_value_by_key($args, 'post_id');
    if (hocwp_id_number_valid($post_id)) {
        global $wpdb;
        $datetime = hocwp_get_current_datetime_mysql();
        $post = get_post($post_id);
        $action = hocwp_get_value_by_key($args, 'action', 'view');
        if (empty($action)) {
            $action = 'view';
        }
        $table_name = $wpdb->prefix . HOCWP_TRENDING_TABLE;
        if (!hocwp_is_table_exists($table_name)) {
            return;
        }
        $trending_day = absint(apply_filters('hocwp_trending_interval', 7));
        $sql = "DELETE FROM {$table_name} WHERE UNIX_TIMESTAMP(post_date) < UNIX_TIMESTAMP(DATE_SUB('{$datetime}', INTERVAL {$trending_day} DAY))";
        $wpdb->query($sql);
        $sql = "INSERT INTO {$table_name} (post_id, post_date, post_type, action)";
        $sql .= " VALUES ('{$post_id}', '{$datetime}', '{$post->post_type}', '{$action}')";
        $wpdb->query($sql);
    }
}
コード例 #2
0
function hocwp_insert_search_tracking_keyword($keyword)
{
    $keyword = trim($keyword);
    if (!empty($keyword)) {
        $keyword = strtolower($keyword);
        global $wpdb;
        $table_name = $wpdb->prefix . HOCWP_SEARCH_TRACKING_TABLE;
        if (!hocwp_is_table_exists($table_name)) {
            return;
        }
        $query = "SELECT * FROM {$table_name} WHERE keyword = '{$keyword}'";
        $result = $wpdb->get_row($query);
        if (empty($result)) {
            $sql = "INSERT INTO {$table_name} (keyword, count)";
            $sql .= " VALUES ('{$keyword}', 1)";
            $wpdb->query($sql);
        } else {
            $count = $result->count;
            $count++;
            $sql = "UPDATE {$table_name} SET count = {$count} WHERE keyword = '{$keyword}'";
            $wpdb->query($sql);
        }
    }
}