Skip to content

Instantly share code, notes, and snippets.

View davemac's full-sized avatar

davemac davemac

View GitHub Profile
@davemac
davemac / WooCommerce don't show current product in WC products sidebar widget
Last active August 10, 2017 06:33
WooCommerce don't show current product in WC products sidebar widget
// don't show current product in products sidebar widget
function dmc_filter_woocommerce_products_widget_query_args( $query_args ) {
$dmc_product_id = get_the_ID();
$dmc_exclude_ids = array( $dmc_product_id );
$query_args['post__not_in'] = $dmc_exclude_ids;
return $query_args;
};
@davemac
davemac / acf_pullquotes_shortcode
Created July 12, 2017 04:47
Uses a WP shortcode to insert ACF pullquotes into content
/**
* Shortcode to insert ACF dmc_pullquotes repeater field content from current post.
*
* @param array $atts chooses row to use in the dmc_pullquotes repeater
* @param string $content null
*
* @return string the pullquote content wrapped in a container class
*/
function dmc_acf_pullquote_shortcode( $atts, $content = null ) {
@davemac
davemac / getups
Created June 23, 2017 02:03
rsync wp uploads directory from staging to current site
# rsync wp uploads directory from staging to current site
getups() {
current=${PWD##*/}
cd ~/Sites/$current/wp-content/uploads
rsync -avzW --progress --exclude '*.pdf' $current-s:~/www/wp-content/uploads/* .
}
// Preload ACF key from wp-config.php into database
function anchor_acf_auto_set_license_keys() {
// Check if ACF is running and ACF Pro key found in wp-config.php
if ( class_exists('acf') && defined('ACF_PRO_KEY') ) {
$save = array(
'key' => ACF_PRO_KEY,
'url' => home_url()
);
function anchor_prep {
mkdir ~/scripts
read -p $'\e[31mDatabase name\e[0m: ' dbname
read -p $'\e[31mDatabase password\e[0m: ' dbpw
echo -e "dbpw=$dbpw\ndbuser=$dbname\ndbname=$dbname\nmysqldump --user=\$dbuser --password=\$dbpw --no-create-db --databases \$dbname > ~/public/wp-content/mysql.sql" > ~/scripts/db_backup.sh
chmod +x ~/scripts/db_backup.sh
mkdir ~/downloads
cd ~/downloads
read -p $'\e[31mWP Engine download link\e[0m: ' downloadlink
wget $downloadlink
@davemac
davemac / wp-post-create--loop-files.sh
Created June 1, 2017 01:45
wp-cli bash script to create posts from files
https://wordpress.stackexchange.com/a/224482/131
#!/bin/bash
FILES=*.txt
for f in $FILES
do
echo "Processing $f file..."
# TEXTFILE = $f
# take action on each file. $f store current file name
# cat $TEXTFILE
@davemac
davemac / wp-cli update multiple
Created May 22, 2017 04:02
wp-cli update core and plugins across multiple sites
Updating WP-Core on multiple sites:
find /home/*/public_html -name "wp-admin" -execdir /home/wp core update --allow-root \;
Updating plugins on multiple sites:
find /home/*/public_html -name "wp-admin" -execdir /home/wp plugin update-all --allow-root \;
Found here: https://wordpress.stackexchange.com/questions/267592/changing-the-wp-cli-cache-folder
@davemac
davemac / bash-generate-baconipsum-posts
Last active July 10, 2017 04:36
Wordpress : bash function, uses wp-cli to generate posts using https://baconipsum.com/json-api/
# Example use: bipsum 4 pages
bipsum(){
curl "https://baconipsum.com/api/?type=meat-and-filler&paras=5&format=html" | wp post generate --post_type=$2 --count=$1 --post_content;
}
@davemac
davemac / wc_check_against_mix_match
Last active May 16, 2017 10:56
WooCommerce check if current product is being used in a Mix and Match parent product
global $wpdb;
$dmc_mnm_child_id = $product->get_id();
$querystr = "
SELECT *
FROM $wpdb->postmeta
WHERE $wpdb->postmeta.meta_key = '_mnm_data'
AND $wpdb->postmeta.meta_value LIKE '%{$dmc_mnm_child_id}%'
";
$pageposts = $wpdb->get_results( $querystr, OBJECT );
@davemac
davemac / acf_slick.php
Created May 8, 2017 11:48 — forked from mattradford/acf_slick.php
ACF slick slider
<?php if( have_rows('billboard') ): ?>
<div class="billboard">
<?php while( have_rows('billboard') ): the_row();
$imageArray = get_sub_field('image');
$imageURL = $imageArray['url'];
?>
<div class="slide-item" style="background-image: url('<?php echo $imageURL;?>');" >
<h1><?php the_sub_field('title'); ?></h1>
</div>