Skip to content

Instantly share code, notes, and snippets.

View moskalukigor's full-sized avatar

Ihor moskalukigor

View GitHub Profile
@moskalukigor
moskalukigor / functions.php
Created August 28, 2017 13:01 — forked from zorzv/functions.php
Autocomplete Taxonomy Terms in Wordpress
//Custom Autocomplete
add_action('wp_ajax_nopriv_get_listing_names', 'ajax_listings');
add_action('wp_ajax_get_listing_names', 'ajax_listings');
function ajax_listings() {
global $wpdb; //get access to the WordPress database object variable
//get names of all taxonomy terms
$name = '%'.$wpdb->esc_like(stripslashes($_GET['name'])).'%'; //escape for use in LIKE statement
$sql = "SELECT term.term_id as id, term.name as post_title, term.slug as guid, tax.taxonomy FROM $wpdb->term_taxonomy tax
@moskalukigor
moskalukigor / gist:792df0c6e379bc318ec0e118ea2f9f48
Created August 2, 2017 14:20 — forked from mikejolley/gist:1604009
WooCommerce - Add a special field to the checkout, order emails and user/order meta
/**
* Add the field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h3>'.__('My Field').'</h3>';
/**
@moskalukigor
moskalukigor / functions.php
Created August 2, 2017 07:18
Fix pagination posts_per_page GET['ppp']
add_action('pre_get_posts','func_pre_get_posts');
function func_pre_get_posts( $query ) {
if( $query->is_main_query() && !$query->is_feed() && !is_admin() && $_GET['ppp']) {
$query->set( 'posts_per_page', $_GET['ppp'] );
}
}
@moskalukigor
moskalukigor / Download images CURL
Created July 6, 2017 12:07
Fast Download images CURL
//$imurl - віддалений url файла
//$picpath - path до локального файла з новим іменем
function save_image($imurl, $picpath) {
$ch = curl_init();
$fp = fopen($picpath, 'w');
$ch = curl_init($imurl);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FILE, $fp);
@moskalukigor
moskalukigor / WC_GET_TEMPLATE_PART foreach | custom the_post()
Created July 6, 2017 08:08
WC_GET_TEMPLATE_PART foreach | custom the_post()
foreach($customRelated as $customRel)
{
global $post;
$post = $customRel;
setup_postdata( $post );
wc_get_template_part( 'content', 'product' );
}
wp_reset_postdata();
@moskalukigor
moskalukigor / set cookie | get cookie JS
Created May 11, 2017 11:42
set cookie | get cookie JS
@moskalukigor
moskalukigor / js function
Created April 13, 2017 08:13
Save file to disk JS JQUERY
function SaveToDisk(fileURL, fileName) {
// for non-IE
if (!window.ActiveXObject) {
var save = document.createElement('a');
save.href = fileURL;
save.target = '_blank';
save.download = fileName || 'unknown';
var evt = new MouseEvent('click', {
'view': window,
$vid = $video['video_link'];
$vid_ex = explode("v=",$vid);
$imgurl = 'http://img.youtube.com/vi/'.$vid_ex[1].'/0.jpg';
$imgurl = (@file_get_contents($imgurl))?$imgurl:'http://img.youtube.com/vi/'.$vid_ex[1].'/maxresdefault.jpg';
@moskalukigor
moskalukigor / gist:866eeac1ceb67b1eef98ec05740bfb85
Created April 7, 2017 13:55
Find and replace html Chrome Extension (ABC to XYZ)
document.body.innerHTML = document.body.innerHTML.replace(/ABC/g, "XYZ")