Skip to content

Instantly share code, notes, and snippets.

View tallesairan's full-sized avatar
🏠
Working from home

Talles Airan tallesairan

🏠
Working from home
View GitHub Profile
@tallesairan
tallesairan / del_woo_products_with_ attachment.php
Created August 15, 2018 17:27 — forked from trueqap/del_woo_products_with_ attachment.php
Delete WooCommerce products with images (attachment)
<?php
function delete_associated_media( $id ) {
$media = get_children( array(
'post_parent' => $id,
'post_type' => 'attachment'
) );
if( empty( $media ) ) {
return;
@tallesairan
tallesairan / find_duplicate_titles.php
Created August 15, 2018 19:52
Find duplicated attachment titles in wordpress and remove
<?php
$duplicate_titles = $wpdb->get_col("SELECT post_title FROM {$wpdb->posts} WHERE post_type = 'attachment' GROUP BY post_title HAVING COUNT(*) > 1");
echo "Find ".count($duplicate_titles)." duplicated titles \n";
foreach( $duplicate_titles as $title ) {
echo "find images with ".$title." \n";
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' and post_title=%s", $title ) );
// Iterate over the second ID with this post title till the last
foreach( array_slice( $post_ids, 1 ) as $post_id ) {
$status = (wp_delete_attachment( $post_id,1 )) ? 'Deleted' : 'Not deleted';
@tallesairan
tallesairan / youtube-id.php
Created August 16, 2018 17:21 — forked from leogopal/youtube-id.php
PHP function to get youtube ID from URL
<?php
function get_youtube_video_ID($youtube_video_url) {
/**
* Pattern matches
* http://youtu.be/ID
* http://www.youtube.com/embed/ID
* http://www.youtube.com/watch?v=ID
* http://www.youtube.com/?v=ID
* http://www.youtube.com/v/ID
* http://www.youtube.com/e/ID
@tallesairan
tallesairan / ytacfoembed.php
Last active March 11, 2024 21:55
Youtube Video gallery acf oEmbed field
<?php
function get_youtube_video_ID($youtube_video_url) {
/**
* Pattern matches
* http://youtu.be/ID
* http://www.youtube.com/embed/ID
* http://www.youtube.com/watch?v=ID
* http://www.youtube.com/?v=ID
* http://www.youtube.com/v/ID
* http://www.youtube.com/e/ID
@tallesairan
tallesairan / getRoom.js
Created August 24, 2018 18:59
custom jquery event
window.startDate = false;
window.endDate = false;
let dateOutSel = 'input[name="dateOut"]';
let dateInSel = 'input[name="dateIn"]';
$('label[for=dateOut]').hide('fast');
$(dateOutSel).hide('fast');
$(dateInSel).datepicker().on('changeDate', function(e) {
@tallesairan
tallesairan / human_time.php
Last active August 30, 2018 13:18
Display post time ago, eg: 37 minutes ago.
<?php
function postedAgo() {
$post_time = get_the_time( 'U' );
$time_now = date( 'U' );
// Use human time if less that 60 days ago, otherwise display the date
// Uses the WordPress internal function human_time_diff
// 60 seconds * 60 minutes * 24 hours * 90 days.
if ( $post_time > $time_now - ( 60 * 60 * 24 * 90 ) ) {
$human_time = sprintf( esc_html__( '%s ago', 'talles' ), human_time_diff( $post_time, current_time( 'timestamp' ) ) );
} else {
@tallesairan
tallesairan / lastProducts.php
Created September 12, 2018 12:57
lastProducts
<?php
function lastProducts($limit){
$sitesData = get_sites(['number' => 200000000]);
$posts = [];
foreach ( $sitesData as $sites_datumk=>$sites_datum ) {
$st = [];
switch_to_blog( $sites_datum->blog_id );
$st = get_posts([
'post_type'=>'product',
'posts_per_page' => $limit,
@tallesairan
tallesairan / text-gradient.css
Created September 19, 2018 12:16
text gradient css
.text-gradient {
background-blend-mode: soft-light;
background-image: linear-gradient(to top, rgb(16, 18, 16), rgb(255, 255, 255)), linear-gradient(tan, rgb(212, 181, 120));
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
}
@tallesairan
tallesairan / query-acf-field.php
Created September 25, 2018 14:25
Query posts by ACF Repeater field, change repeaterName for your repeater name
/**
* Allow hooking into ACF repeated fields with meta queries
*/
function repeaterAdapter( $where ) {
$where = str_replace("meta_key = 'repeaterName_$", "meta_key LIKE 'repeaterName_%", $where);
return $where;
}
@tallesairan
tallesairan / observer.js
Last active September 26, 2018 13:48
Class change Observer with MutationObserver read more at https://developer.mozilla.org/pt-BR/docs/Web/API/MutationObserver
/// read more at
var $div = $(".card");
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName === "class") {
var attributeValue = $(mutation.target).prop(mutation.attributeName);
console.log("Class attribute changed to:", attributeValue);
console.log($(mutation.target));
$( document ).trigger( "validateCard", attributeValue );
}