Skip to content

Instantly share code, notes, and snippets.

View levantoan's full-sized avatar

Lê Văn Toản levantoan

View GitHub Profile
@levantoan
levantoan / sql_order
Created April 20, 2016 02:35
sắp xếp theo ID, những ID nào chẵn thì xếp tăng dần, ID lẻ thì giảm dần
/*
sắp xếp theo ID, những ID nào chẵn thì xếp tăng dần, ID lẻ thì giảm dần
VD:
5
3
1
2
4
6
Kết quả:
@levantoan
levantoan / shortcode_get_images_instagram.php
Last active May 26, 2016 04:18
Shortcode hiển thị tối đa 12 ảnh mới nhất trong instagram cho user
<?php
/*
Hiển thị tối đa 12 ảnh mới nhất trong instagram cho user
Cách dùng: [instagram_widget user="_Your User Here_" show="_Your Number show (max 12)_"]
by www.levantoan.com
*/
function scrape_instagram($username, $slice = 9) {
if (false === ($instagram = get_transient('instagram-photos-'.sanitize_title_with_dashes($username)))) {
$remote = wp_remote_get('http://instagram.com/'.trim($username));
@levantoan
levantoan / instagram_get_recent_images_from_user_v1.php
Created May 28, 2016 02:12
Lấy ảnh mới nhất từ instagram của user thông qua access_token
<?php
/*instagram shortcode
* Get access_token to http://instagram.pixelunion.net/
* Or place [CLIENT_ID_HERE] to your Client ID => https://instagram.com/oauth/authorize/?client_id=[CLIENT_ID_HERE]&redirect_uri=http://localhost&response_type=token
Used: [instagram_widget access_token="_Your Access Token_" show="20"]
by: www.levantoan.com
* */
function scrape_instagram($access_token = '', $slice = 20, $type = "image") {
<?php
/*
Array
(
[name] => Array
(
[0] => 0as
[1] => 1as
[2] => 2as
[3] => 3as
<?php
/*
* Add to functions.php
* Add div.videoWrapper to iframe
*/
function div_wrapper($content) {
// match any iframes
/*$pattern = '~<iframe.*</iframe>|<embed.*</embed>~'; // Add it if all iframe*/
$pattern = '~<iframe.*src=".*(youtube.com|youtu.be).*</iframe>|<embed.*</embed>~'; //only iframe youtube
preg_match_all($pattern, $content, $matches);
@levantoan
levantoan / add-metabox-to-taxonomy.php
Created July 14, 2017 09:16 — forked from ms-studio/add-metabox-to-taxonomy.php
simple but complete example of adding metabox to taxonomy - using WP 4.4 term meta functions
<?php
// source: http://wordpress.stackexchange.com/questions/211703/need-a-simple-but-complete-example-of-adding-metabox-to-taxonomy
// code authored by jgraup - http://wordpress.stackexchange.com/users/84219/jgraup
// REGISTER TERM META
add_action( 'init', '___register_term_meta_text' );
function ___register_term_meta_text() {
@levantoan
levantoan / remove_custom_post_type_SLUG_from_permalink.php
Created May 27, 2016 16:50
Remove custom post type SLUG from permalink
<?php
/*
Ví dụ cho post_type là race
Thêm code dưới vào file functions.php
Chú ý nếu post type là "race" nhưng slug lại là "race-slug" thì cần thay lại dòng 17 như sau
$post_link = str_replace( '/race-slug/', '/', $post_link );
*/
/**
* Remove the slug from published post permalinks. Only affect our custom post type, though.
*/
@levantoan
levantoan / Query_More_metakey.sql
Created April 26, 2016 15:22
Truy vấn 1 lúc nhiều điều kiện với meta_key và meta_value trong WordPress
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )
INNER JOIN wp_postmeta AS mt2 ON ( wp_posts.ID = mt2.post_id )
INNER JOIN wp_postmeta AS mt3 ON ( wp_posts.ID = mt3.post_id )
WHERE 1=1
AND (
wp_postmeta.meta_key = 'end_date'
AND
@levantoan
levantoan / WP_Query_by_meta_value_date.php
Last active February 2, 2018 11:45
Query and order custom post by meta value date format
<?php
$arg = array(
'post_type' => 'events',//thay bằng post type của bạn
'posts_per_page' => 3,
'orderby' => 'meta_value',
'meta_key' => 'start_date_event',//thay bằng meta key của bạn
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'start_date_event',//thay bằng meta key của bạn
@levantoan
levantoan / them_tang_giam.css
Created February 15, 2017 16:14
Thêm nút tăng giảm số lượng sản phẩm khi thêm vào giỏ hàng
/*
web: http://levantoan.com
*/
.woocommerce #quantity input::-webkit-outer-spin-button,
.woocommerce #quantity input::-webkit-inner-spin-button,
.woocommerce #content .quantity input::-webkit-outer-spin-button,
.woocommerce #content .quantity input::-webkit-inner-spin-button, .woocommerce-page #quantity input::-webkit-outer-spin-button,
.woocommerce-page #quantity input::-webkit-inner-spin-button,
.woocommerce-page #content .quantity input::-webkit-outer-spin-button,