This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function orderbyReplace($orderby) | |
{ | |
global $wpdb; | |
// use this if you have stable literal prefixes (e.g. af102, af56, af2569) | |
$new = str_replace($wpdb->prefix . 'postmeta.meta_value ASC', 'LENGTH(mt1.meta_value) ASC, mt1.meta_value ASC', $orderby); | |
// use this if you have something like (102bch, 56dbg, 2569, 12ea) | |
$new = str_replace($wpdb->prefix . 'postmeta.meta_value ASC', 'CAST(mt1.meta_value as UNSIGNED) ASC, mt1.meta_value ASC', $orderby); | |
return $new; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Custom Post Types and Taxonomies | |
*/ | |
function vd_register_custom_post_type() | |
{ | |
$post_types = [ | |
'faq' => [ | |
'name' => 'FAQ', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter | |
* Remove rel="nofollow" attribute from internal links into comment text | |
*/ | |
function vd_comment_text( $comment_text, $comment, $args ) { | |
// find all <a> tags | |
$regex = '#<\s*?a\b[^>]*>.*?</a\b[^>]*>#s'; | |
preg_match_all( $regex, $comment_text, $matches ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// reorder woocommerce attribute taxonomies | |
function css_woocommerce_attribute_taxonomies( $taxonomies ) { | |
$out = array(); | |
foreach($taxonomies as $t){ | |
$out[$t->attribute_id] = $t; | |
} | |
ksort($out); | |
return $out; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getTaxTermsByOtherTaxTerm($taxonomy_args, $out_taxonomy, $post_type = NULL) { | |
global $wpdb; | |
$tax_q = $taxonomy_ids = array(); | |
$post_type_q = !empty($post_type_q) ? "AND p.post_type = '$post_type'" : ""; | |
foreach ($taxonomy_args as $tax => $term_id) { | |
$sql = "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt | |
INNER JOIN $wpdb->term_taxonomy t ON (t.term_id = tt.term_id AND tt.taxonomy = '$tax' AND t.term_id = $term_id)"; | |
$taxonomy_ids = array_merge( $taxonomy_ids, $wpdb->get_col($sql) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function specialWholesaleTaxClass( $tax_class, $product ) { | |
global $current_user; | |
if (in_array('wholesale_customer', $current_user->roles)) | |
$tax_class = 'Special Wholesale'; | |
else | |
$tax_class = 'Zero Rate'; | |
return $tax_class; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//$oargs = array('orderby' => 'post__in', 'post__in' => get_order_tax_ids('events', 'region')); | |
//$args = array_merge($args, $oargs); | |
function get_order_tax_ids($post_type, $taxonomy) { | |
global $wpdb; | |
$ids = []; | |
$sql = "SELECT p.ID FROM $wpdb->posts p | |
JOIN $wpdb->term_relationships tr ON (tr.object_id = p.ID) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//$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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* filter to get "services" in product categories, child categories, and singe product pages correctly */ | |
// /services/%product_cat%/ - Product base permalink settings | |
// services - Product Category base permalink settings | |
add_filter('rewrite_rules_array', function( $rules ) { | |
$new_rules = array( | |
'services/([^/]*?)/page/([0-9]{1,})/?$' => 'index.php?product_cat=$matches[1]&paged=$matches[2]', | |
'services/([^/]*?)/([^/]*?)/page/([0-9]{1,})/?$' => 'index.php?product_cat=$matches[2]&paged=$matches[3]', | |
'services/([^/]*?)/?$' => 'index.php?product_cat=$matches[1]', |
NewerOlder