Skip to content

Instantly share code, notes, and snippets.

View IacopoC's full-sized avatar
🎯
Crunch mode

Iacopo C IacopoC

🎯
Crunch mode
View GitHub Profile
@IacopoC
IacopoC / custom-qorder.php
Created November 20, 2017 10:47
Order custom query by last word
<?php
$args = [
'posts_per_page' => 10,
'post_type' => 'speaker',
'meta_key' => 'speaker-front-page',
'meta_value' => '1',
'orderby' => 'customq_last_word', //<-- Custom ordering
'order' => 'ASC'
];
@IacopoC
IacopoC / check-language-wpml.php
Created June 20, 2017 11:32
Check which language are you visualizing in wpml and do some actions
<?php if(ICL_LANGUAGE_CODE=='en'):
// do something
elseif(ICL_LANGUAGE_CODE=='it'):
// do something else
endif; ?>
<?php
// enqueue font awersome from local css folder
function enqueue_fontawersome_stylesheets(){
wp_enqueue_style('font-awesome', get_stylesheet_directory_uri() . '/css/font-awesome.css');
}
add_action('wp_enqueue_scripts','enqueue_fontawersome_stylesheets');
@IacopoC
IacopoC / acf-loop-taxonomy.php
Last active March 16, 2019 21:30
ACF loop through news taxonomy
<?php
$terms = get_the_terms( $post->ID, 'area');
$postid = get_the_ID();
foreach ($terms as $term) {
$posts = get_posts(array(
'posts_per_page'=> -1,
@IacopoC
IacopoC / Acf-loop.php
Last active March 16, 2019 21:30
ACF secondary loop news post type
<?php
$posts = get_posts(array(
'posts_per_page' => 3,
'post_type' => 'news'
));
if( $posts ): ?>
@IacopoC
IacopoC / enqueue-css.php
Created April 15, 2017 19:32
Enqueue Css in WordPress plugin
/**
* Enqueue css
**/
function load_custom_wp_admin_style() {
wp_register_style( 'style.css', plugins_url('/css/style.css', __FILE__), false, '1.0.0' );
wp_enqueue_style( 'style.css' );
}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
@IacopoC
IacopoC / Wc add notice for errors
Created March 4, 2017 13:25
Function useful to display error notice in WooCommerce
<?php
// Wc add notice can be used to create error, notice or success messages in WooCommerce. In this case we see error notice.
wc_add_notice( $message, $notice_type = 'error' );
<?php
// return true if we are in the cart page
is_cart();
// return true if we are in the checkout page
is_checkout();
@IacopoC
IacopoC / woocommerce_check_cart_items_hook
Created March 4, 2017 13:17
WooCommerce hook that checks number of items in the cart
<?php do_action( 'woocommerce_check_cart_items' ); ?>
<?php capital_P_dangit( $text ); ?>