[WordPress]404任意表示
public function show_404() { header('HTTP/1.0 404 Not Found'); include(TEMPLATEPATH.'/404.php'); exit; }
public function show_404() { header('HTTP/1.0 404 Not Found'); include(TEMPLATEPATH.'/404.php'); exit; }
js
function getDateByYYYYMMDD(yyyymmdd) { var tmp = void 0, match = void 0; if (match = yyyymmdd.match(/[\d]{4}\-[\d]{2}\-[\d]{2}/)) { if (match.length) { tmp = match[0].split('-'); } } else if (match = yyyymmdd.match(/[\d]{4}[\d]{2}[\d]{2}/)) { if (match.length) { tmp = [match[0].substr(0, 4), match[0].substr(4, 2), match[0].substr(6, 2)]; } } if (!tmp || tmp.length < 3) { return null; } return new Date(Number(tmp[0]), Number(tmp[1]) - 1, Number(tmp[2]), 0, 0, 0, 0); }
es6
getDateByYYYYMMDD(yyyymmdd){ let tmp,match; if(match = yyyymmdd.match(/[\d]{4}\-[\d]{2}\-[\d]{2}/)){ if(match.length){ tmp = match[0].split('-'); } }else if(match = yyyymmdd.match(/[\d]{4}[\d]{2}[\d]{2}/)){ if(match.length){ tmp = [match[0].substr(0,4),match[0].substr(4,2),match[0].substr(6,2)]; } } if(!tmp || tmp.length < 3){ return null; } return new Date(Number(tmp[0]),Number(tmp[1])-1,Number(tmp[2]),0,0,0,0); }
public function get_archive_years($options = array()) { $options = array_merge( array('post_type' => 'xxx', 'type' => 'yearly', 'after' => "<format>%s,</format>", 'echo' => 0), $options ); $tmp = wp_get_archives($options); $tmp = explode(",", $tmp); array_pop($tmp); return $tmp; }
define(‘ALTERNATE_WP_CRON’, true);の時に発生
if(isset($_GET['doing_wp_cron'])){ header('Location: '.get_current_url(false,array('doing_wp_cron'))); exit; } public function get_current_url($remove_get_query = false,$exclude_keys = array()) { $suffix = $_SERVER['REQUEST_URI']; if($remove_get_query){ $tmp = explode('?',$suffix); $suffix = array_shift($tmp); }else if(!empty($exclude_keys)){ $tmp = explode('?',$suffix); $suffix = array_shift($tmp); $get = get_get_queries($exclude_keys); if(!empty($get)) $suffix .= '?' . http_build_query($get); } return get_base_url($suffix); } public function get_get_queries($exclude_keys = array()) { $result = array(); foreach ($_GET as $key => $value){ if(!empty($exclude_keys) && in_array($key,$exclude_keys)){ continue; } $result[$key] = $value; } return $result; } public function get_base_url($suffix = '') { return (empty($_SERVER["HTTPS"]) ? "http://" : "https://") . $_SERVER["HTTP_HOST"] . $suffix; }
カスタム投稿タイプで「複製」を実行すると「投稿」にリダイレクトされるのを修正
wp_redirect( add_query_arg( array( 'cloned' => 1, 'ids' => $post->ID), $sendback ) );
duplicate-post-admin.phpの315行目あたりの上記を下記へ変更
wp_redirect( add_query_arg( array( 'cloned' => 1, 'ids' => $post->ID, 'post_type' => $post->post_type), $sendback ) );
function filter_flush_rewrite_rules_hard( $true ) { return false; } add_filter( 'flush_rewrite_rules_hard', 'filter_flush_rewrite_rules_hard', 10, 1 );
public function get_post_by_post_name($post_name, $post_type = '') { global $wpdb; $sql = array(); $sql[] = "SELECT"; $sql[] = "p.*"; $sql[] = "FROM $wpdb->posts AS p"; $sql[] = "WHERE p.post_status = 'publish' AND p.post_name = '$post_name'"; if (!empty($post_type)) $sql[] = "AND p.post_type = '$post_type'"; $result = $wpdb->get_results(implode(' ', $sql)); if (empty($result)) return null; return $result[0]; }
get_postsテンプレ
$conditions = array( 'post_type' => 'カスタム投稿タイプ', 'posts_per_page' => -1,//-1:全て取得する 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', 'tax_query' => array( array( 'taxonomy' => 'タクソノミー', 'field' => 'slug', 'terms' => 'ターム', ) ), ); $posts = get_posts($conditions);
<?php foreach($posts as $post):?>
<?php endforeach; wp_reset_postdata();?>
カラム名一覧取得
application/core/MY_Model.phpとかに追記
public function get_column_names($table = '', $format = '%s') { $names = $this->db->list_fields(empty($table) ? $this->name : $table); if(!empty($format)){ foreach($names as &$name){ $name = sprintf($format,$name); } } return $names; }
wp-config.php
define('SAVEQUERIES', true);
テンプレート内
global $wpdb; var_dump($wpdb->queries);