Skip to content

Instantly share code, notes, and snippets.

@senooat
senooat / WP_Query
Last active November 18, 2016 00:55 — forked from hissy/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
* Japanese translated by hissy
*
* CODEX: http://wpdocs.sourceforge.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/WP_Query#.E3.83.91.E3.83.A9.E3.83.A1.E3.83.BC.E3.82.BF
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
* Original: https://gist.github.com/luetkemj/2023628/9e911982440141a13cb1dd8ba1ad6b35cd7bbdd7
*/
/*-----------------------------------
お知らせ表示ショートコード
[news num="5" cat="news" showcat=""]
-----------------------------------*/
function getNewItems($atts) {
extract(shortcode_atts(array(
"num" => '', //最新記事リストの取得数
"cat" => '', //表示する記事のカテゴリー指定
"showcat" => '' //カテゴリー表示の有無
), $atts));
$category = get_the_category();
$cat_id = $category[0]->cat_ID;
$cat_name = $category[0]->cat_name;
$cat_slug = $category[0]->category_nicename;
$category_link = get_category_link( $cat_id );
$taxonomy = 'タクソノミー名';
$terms = wp_get_post_terms( $post->ID, $taxonomy );
if ( $terms && ! is_wp_error( $terms ) ):
foreach ( $terms as $term ):
$term_id = $term->term_id;
$term_name = $term->name;
$term_slug = $term->slug;
$term_link = get_term_link( $term_id, $taxonomy );
endforeach;
endif;
//サイトのURLを変更する
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';
//画像のパスを変更する
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com');
//Metaを変更
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://www.oldsiteurl.com','http://www.newsiteurl.com');
//デフォルトのユーザー名である「admin」を変更する
/////////////////////////////////////////////
//コピペ一発でWordpressの投稿時にアイキャッチを自動設定するカスタマイズ方法(YouTube対応版)
//http://nelog.jp/auto-post-thumbnail-custum
/////////////////////////////////////////////
//WP_Filesystemの利用
require_once(ABSPATH . '/wp-admin/includes/image.php');
//イメージファイルがサーバー内にない場合は取得する
//<head>に読み込み
<link rel="stylesheet" href="tingle.min.css">
//</body>直前に読み込み
<script src="tingle.min.js"></script>
<script>
var modal1 = new tingle.modal({ cssClass: ['modal1'] });
modal1.setContent(document.getElementById('modal1_html').innerHTML);
</script>
//<head>に読み込み
<link rel="stylesheet" href="https://unpkg.com/smartphoto@0.5.9/css/smartphoto.min.css">
//</body>直前に読み込み
<script src="https://unpkg.com/smartphoto@0.5.9/js/smartphoto.min.js"></script>
<script>
window.addEventListener('DOMContentLoaded',function(){
new smartPhoto(".js-smartPhoto");
});
/*-----------------------------------
アイキャッチ付き
News表示ショートコード
[news num="5"]
-----------------------------------*/
function getNewsItems($atts) {
extract(shortcode_atts(array(
"num" => '', //最新記事リストの取得数
), $atts));
global $post;
<?php
/*-----------------------------------
wp_head(),wp_footer()にJS,CSSを読み込み
-----------------------------------*/
function add_files() {
if ( is_admin() ) return;
//共通
wp_deregister_script('jquery');
wp_enqueue_script('jquery', SITEURL.'/js/jquery.min.js',array(), '', false);