Skip to content

Instantly share code, notes, and snippets.

View marcosnakamine's full-sized avatar

Marcos Nakamine marcosnakamine

View GitHub Profile
@marcosnakamine
marcosnakamine / index.php
Created March 15, 2017 14:06
WordPress - Get all custom posts of custom taxonomy
<?php
$query = new WP_Query(array(
'post_type' => 'custom_post',
'tax_query' => array(
array(
'taxonomy' => 'custom_taxonomy',
'field' => 'slug',
'terms' => 'taxonomy-slug'
)
)
@marcosnakamine
marcosnakamine / index.php
Last active May 18, 2017 12:06
WordPress - Get attachment src by thumbnail ID
<?php
var_dump( wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ) ) );
/*
array(4) {
[0]=>
string(81) "http://url/wp-content/uploads/2017/05/img-90x180.jpg"
[1]=>
int(90)
[2]=>
@marcosnakamine
marcosnakamine / mysql.sql
Created March 10, 2017 21:41
MySQL - Get formatted date
SELECT
DATE_FORMAT(column,'%d/%m/%Y')
FROM table
@marcosnakamine
marcosnakamine / mysql.sql
Created March 10, 2017 21:38
MySQL - Inner join with multiple tables
SELECT *
FROM (
table1 INNER JOIN table2
ON table1.column1 = table2.column1
)
INNER JOIN table3
ON table1.column2 = table3.column1
@marcosnakamine
marcosnakamine / mysql.sql
Created March 10, 2017 20:17
MySQL - Search and replace string
UPDATE table_name
SET column_name = REPLACE(
column_name,
'search',
'replace'
)
@marcosnakamine
marcosnakamine / index.php
Last active July 4, 2018 19:44
WordPress - Really Simple CAPTCHA plugin with custom form
<?php
// https://br.wordpress.org/plugins/really-simple-captcha/
$captcha_instance = new ReallySimpleCaptcha();
$captcha_instance->bg = array( 255, 255, 255 );
$word = $captcha_instance->generate_random_word();
$prefix = mt_rand();
$img_captcha = $captcha_instance->generate_image( $prefix, $word );
if ( isset( $_POST['send'] ) && $_POST['send'] == 'ok' ) {
if ( $captcha_instance->check( $_POST['prefix'], $_POST['captcha'] ) ) {
@marcosnakamine
marcosnakamine / index.php
Last active March 10, 2017 13:18
WooCommerce - Get product tags, image and permalink with ACF
<?php
$cat = get_categories( array(
'taxonomy' => 'product_tag'
) );
foreach( $cat as $key => $value ){
var_dump( get_field( 'imagem', 'product_tag_'.$value->term_id ) );
echo get_term_link( $value->term_id, 'product_tag' );
}
@marcosnakamine
marcosnakamine / functions.php
Last active March 6, 2017 18:44 — forked from jameskoster/functions.php
WooCommerce - Change number of products per row
<?php
// Change number or products per row to 3
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
function loop_columns() {
return 3; // 3 products per row
}
}
@marcosnakamine
marcosnakamine / functions.php
Last active March 21, 2017 19:33
WordPress - Custom post with custom permalink (slug)
<?php
add_action( 'init', 'register_new_post_type' );
function register_new_post_type(){
$args = array(
'label' => 'Post title',
'show_ui' => true,
'public' => true,
'hierarchical' => true,
'has_archive' => true,
'supports' => array( 'title' ),
@marcosnakamine
marcosnakamine / functions.php
Last active March 10, 2017 13:18 — forked from agusmu/functions1a.php
WooCommerce - Custom categories and tags label
<?php
/* Customize Product Categories Labels */
add_filter( 'woocommerce_taxonomy_args_product_cat', 'custom_wc_taxonomy_args_product_cat' );
function custom_wc_taxonomy_args_product_cat( $args ) {
$args['label'] = __( 'Product Categories', 'woocommerce' );
$args['labels'] = array(
'name' => __( 'Product Categories', 'woocommerce' ),
'singular_name' => __( 'Product Category', 'woocommerce' ),
'menu_name' => _x( 'Categories', 'Admin menu name', 'woocommerce' ),
'search_items' => __( 'Search Product Categories', 'woocommerce' ),