本文整理汇总了PHP中Posts::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::update方法的具体用法?PHP Posts::update怎么用?PHP Posts::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Posts
的用法示例。
在下文中一共展示了Posts::update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit
public function edit($id)
{
// find article
if (($article = Posts::find(array('id' => $id))) === false) {
return Response::redirect($this->admin_url . '/posts');
}
// process post request
if (Input::method() == 'POST') {
if (Posts::update($id)) {
// redirect path
return Response::redirect($this->admin_url . '/posts/edit/' . $id);
}
}
// get comments
$comments = Comments::list_all(array('post' => $id));
$pending = array();
foreach ($comments as $comment) {
if ($comment->status == 'pending') {
$pending[] = $comment->id;
}
}
$pending = count($pending);
// get posts page
$page = Pages::find(array('id' => Config::get('metadata.posts_page')));
Template::render('posts/edit', array('article' => $article, 'comments' => $comments, 'page' => $page, 'pending' => $pending));
}
示例2: get
/**
* @param int $post_id
* @param string $post_type
* @param string $key
*
* @return \WP_Post
*/
public static function get($post_id = 0, $post_type = 'post', $key = '')
{
$args = ['ignore_sticky_posts' => true];
if (defined('DOING_AJAX') && DOING_AJAX) {
$args['post_type'] = array_keys(static::$_post_types);
if ($post_id) {
$args['p'] = $post_id;
$post = current((new \WP_Query($args))->get_posts());
} else {
Posts::update($key, $post_id);
$post = null;
}
} else {
if (is_null(static::$_posts)) {
$args['post_type'] = array_keys(static::$_post_types);
$args['posts_per_page'] = -1;
$ids = array_values(static::get_ids());
if (!empty($ids)) {
$args['post__in'] = $ids;
$the_query = new \WP_Query($args);
while ($the_query->have_posts()) {
$the_query->the_post();
$_post_type = get_post_type();
if (!isset(static::$_posts[$_post_type])) {
static::$_posts[$_post_type] = [];
}
static::$_posts[$_post_type][get_the_ID()] = get_post();
}
wp_reset_postdata();
$args['post__not_in'] = $ids;
unset($args['post__in']);
}
foreach (static::$_post_types as $_post_type => $_posts_per_page) {
if (!isset(static::$_posts[$_post_type])) {
static::$_posts[$_post_type] = [];
}
$_found_posts = count(static::$_posts[$_post_type]);
if ($_found_posts < $_posts_per_page) {
$args['post_type'] = $_post_type;
$args['posts_per_page'] = $_posts_per_page - $_found_posts;
$the_query = new \WP_Query($args);
static::$_query_args[$_post_type] = ['offset' => $the_query->post_count];
static::$_posts[$_post_type]['recent'] = $the_query->get_posts();
}
}
}
if ($post_id && isset(static::$_posts[$post_type][$post_id])) {
$post = static::$_posts[$post_type][$post_id];
unset(static::$_posts[$post_type][$post_id]);
} else {
$post_id = key(static::$_posts[$post_type]['recent']);
$post = isset(static::$_posts[$post_type]['recent'][$post_id]) ? static::$_posts[$post_type]['recent'][$post_id] : null;
unset(static::$_posts[$post_type]['recent'][$post_id]);
}
}
return $post;
}
示例3: date
if (!isset($_POST['title']) || $_POST['title'] == "") {
$alertred[] = TITLE_CANNOT_EMPTY;
}
if (isset($alertred)) {
$data['alertred'] = $alertred;
} else {
if (!isset($_POST['date']) || $_POST['date'] == "") {
# code...
$date = date("Y-m-d H:i:s");
} else {
$date = $_POST['date'];
}
$moddate = date("Y-m-d H:i:s");
$vars = array('title' => $title, 'content' => $content, 'modified' => $moddate, 'date' => $date, 'status' => Typo::int($_POST['status']));
//print_r($vars);
Posts::update($vars);
$data['alertgreen'][] = PAGE . " {$_POST['title']} " . MSG_PAGE_UPDATED;
Token::remove($_POST['token']);
}
break;
default:
# code...
//System::inc('posts_form', $data);
break;
}
$id = Typo::int($_GET['id']);
$data['post'] = Db::result("SELECT * FROM `posts` AS A \n LEFT JOIN `posts_param` AS B\n ON A.`id` = B.`post_id` \n WHERE A.`id` = '{$id}' ");
Theme::admin('header', $data);
System::inc('pages_form', $data);
Theme::admin('footer');
break;