Skip to content

Instantly share code, notes, and snippets.

@marushu
marushu / add_thumbnail_admin_column.php
Last active December 7, 2016 03:37
Add specific data to admin column.
<?php
/**
* Add post thumbnail to admin column.
*/
// add product field admin column
function add_blog_admin_columns_head( $defaults ) {
$defaults[ 'post_thumbnail' ] = 'アイキャッチ画像';
return $defaults;
}
add_filter( 'manage_blog_posts_columns', 'add_blog_admin_columns_head' );
@marushu
marushu / count.sh
Last active October 25, 2016 08:25
jqで配列の数を取得
#!/bin/sh
# Count returned json array length.
# --graboff is for [] parameter.
curl --globoff https://private.hibou-web.com/wp-json/wp/v2/posts?filter[posts_per_page]=5 | jq length
@marushu
marushu / package-sample.json
Created October 23, 2016 03:00
For browser-sync ligt test. :)
{
"name": "liottest",
"version": "1.0.0",
"description": "liot test",
"main": "index.js",
"scripts": {
"test": "start",
"start": "browser-sync start --server --files='./*.html'"
},
"author": "",
@marushu
marushu / resize.js
Created October 19, 2016 10:56 — forked from wgkoro/resize.js
指定サイズ以内の画像幅、高さを算出、img要素にそのサイズを適用するスクリプト
/**
* 指定サイズ以内の画像幅、高さを算出、
* img要素にそのサイズを適用する
*
* 使い方:
*
* 例) 幅150px, 高さ200px以内で画像を表示する
* var img = document.createElement('img');
* img.src = 'http://hoge.com/img/fuga.jpg';
* imgResize.resize(img, 150, 200);
@marushu
marushu / relational_post.php
Last active November 6, 2017 09:24
Retrieve relational post by post terms.
<?php
/**
* Get works relational post.
*
* @return mixed
*/
function all_posts_relational_post( $post, $taxonomy, $num, $orderby = 'rand' ) {
$post_type = get_post_type( $post );
$post_type_obj = get_post_type_object( $post_type );
@marushu
marushu / set-filter-by-tax.php
Last active November 21, 2023 05:23
Supports multiple filters.
<?php
function multiple_filter_at_cpt() {
global $typenow;
$args = array(
'public' => true,
'_builtin' => true,
);
$custom_post_types = get_post_types( $args );
$custom_post_types = array_values( $custom_post_types );
@marushu
marushu / add_shortcode.js
Last active October 3, 2016 09:08
Add shortcode to ACF specific field. :)
( function( $ ) {
$( '#acf-image_ba td:nth-child(4) input[type="text"]' ).attr({
'readonly': true,
'onclick': 'this.select()',
'title': '選択部分をコピー( ctrl + c )して貼り付けたい部分へペーストします。'
});
$( '#acf-image_ba .acf-button' ).on( 'click', function( event ) {
var target = $( 'td:nth-child(4)' ).find( 'input[type="text"]' );
@marushu
marushu / 0_reuse_code.js
Created May 9, 2016 02:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@marushu
marushu / acf_repeater_filed_retrieve.php
Last active April 21, 2016 03:25
ACFのリピーターフィールドを取り出す。forで回して一発で出てくるので便利 :D
<?php
$post_id = 19409;
$child_field_count = intval( get_post_meta($post_id, 'supportcase_', true) );
var_dump($child_field_count);
for ( $i=0; $i < $child_field_count; $i++ ){
$case = get_post_meta($post_id, sprintf('supportcase__%d__case', $i), true);
var_dump($case);
}
<?php
add_filter( 'wp', 'only_login_user', 0 );
function only_login_user( $content ) {
global $post;
$post_type = 'post_type';
$taxonomy = $taxonomy;
if( ! is_admin() && ( get_post_type() === $post_type || is_tax( $taxonomy ) )
&& ! is_user_logged_in() ) {