Skip to content

Instantly share code, notes, and snippets.

View mennwebs's full-sized avatar

Menn mennwebs

View GitHub Profile
@mennwebs
mennwebs / front-page.php
Last active July 24, 2019 14:07
แสดง Event (CPT) หน้าแรก เรียงตามวันที่จะมาถึง
<?php
$args = array(
'posts_per_page' => 5,
'post_type' => 'event',
'meta_key' => 'date',
'meta_value' => date("Ymd"),
'meta_compare' => '>',
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
@mennwebs
mennwebs / functions.php
Last active July 24, 2019 14:07
Advanced Forms Pro - สร้างโพสต์ใหม่ เปิด comment กับ save featured image ให้ด้วย
<?php
/**
* AdvanceForms
*/
function form_post_created( $post, $form, $args ) {
$post->comment_status = 'open';
wp_update_post( $post );
update_post_meta($post->ID, '_thumbnail_id', get_field('pic', $post->ID));
}
add_action( 'af/form/editing/post_created', 'form_post_created', 10, 3 );
@mennwebs
mennwebs / style.scss
Last active July 23, 2019 12:36
No margin for last child (p, ol, ul, ...) in div.box
.box {
> :last-child {
margin-bottom: 0;
}
}
@mennwebs
mennwebs / functions.php
Last active July 24, 2019 14:06
แก้ความยาว Excerpt ของ WordPress (default: 50)
<?php
/**
* Excerpt change from 50
*/
function seed_excerpt_length( $length ) {
return 100;
}
add_filter( 'excerpt_length', 'seed_excerpt_length', 100 );
function seed_excerpt_more( $more ) {
@mennwebs
mennwebs / functions.php
Created July 31, 2019 12:15
Change Excerpt Length (WordPress)
<?php
/**
* Excerpt change from 50
*/
function seed_excerpt_length( $length ) {
return 100; // Thai uses "Characters", English uses "Words"
}
add_filter( 'excerpt_length', 'seed_excerpt_length', 900 );
function seed_excerpt_more( $more ) {
@mennwebs
mennwebs / single.php
Last active March 2, 2021 02:19
Thai date from ACF date - formart YYYYMMDD
<?php
$acf_date = get_field($date_field, false, false);
$buddhist_year = (int)substr($acf_date, 0, 4) + 543;
echo date_i18n('j F ', strtotime($acf_date)) . $buddhist_year;
@mennwebs
mennwebs / functions.php
Last active September 2, 2022 19:11
Use ACF image field as avatar
<?php
/**
* Use ACF image field as avatar
* @author Mike Hemberger
* @link http://thestizmedia.com/acf-pro-simple-local-avatars/
* @uses ACF Pro image field (tested return value set as Array )
*/
add_filter('get_avatar', 'acf_profile_avatar', 10, 5);
function acf_profile_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
if ( is_numeric( $id_or_email ) ) {
@mennwebs
mennwebs / af-acf.scss
Created October 8, 2019 14:17
SCSS for Advanced Forms + ACF
$line: #dcdfe5;
$primary: #339833;
$primary-active: #1c6808;
$gray: #878f9d;
div.acf-fields {
> .acf-field {
padding: 15px 16px;
@media (min-width: 768px) {
padding: 20px 30px;
@mennwebs
mennwebs / woo-tags.php
Created October 26, 2019 11:10
WooCommerce - Show Sale Percentage Tag - put in content-product.php
function seed_show_sale_percentage() {
global $product;
if ( $product->is_on_sale() ) {
if ( ! $product->is_type( 'variable' ) ) {
$max_percentage = ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100;
} else {
$max_percentage = 0;
foreach ( $product->get_children() as $child_id ) {
$variation = wc_get_product( $child_id );
$price = $variation->get_regular_price();
@mennwebs
mennwebs / front-page.php
Created December 15, 2019 07:49
ACF Repeater Headlines
<?php
/**
* ACF Repeater Field : headlines
* ACF Sub Field: headline (Post ID)
*/
$posts = array();
if (have_rows('headlines')) {
while (have_rows('headlines')) {
the_row();