Skip to content

Instantly share code, notes, and snippets.

View davemac's full-sized avatar

davemac davemac

View GitHub Profile
@davemac
davemac / acf-first-row.php
Created March 21, 2017 04:46 — forked from neilgee/acf-first-row.php
ACF Repeater - Grab First/LAst or Random Single Data Row
<?php
//My ACF Fields for reference
//testimonials - field group
//testimonial - sub-field
//testimonial_header - sub-field
//First Repeater Row in Array
$rows = get_field( 'testimonials', 348 );// grab all rows from page ID
@davemac
davemac / acf-js.js
Created March 21, 2017 04:43 — forked from neilgee/acf-js.js
ACF Google Map - Get Directions Link
(function($) {
/*
* new_map
*
* This function will render a Google Map onto the selected jQuery element
*
* @type function
* @date 8/11/2013
* @since 4.3.0
@davemac
davemac / WooCommerce get parent product category ID of a product on single product page
Created February 3, 2017 09:05
WooCommerce get parent product category ID of a product on single product page
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) {
$product_cat_id = $term->term_id;
echo $product_cat_id;
break;
}
@davemac
davemac / sync-prod.sh
Created January 16, 2017 10:55 — forked from retlehs/sync-prod.sh
WP-CLI aliases sync example
read -r -p "Would you really like to reset your development database and pull the latest from production? [y/N] " response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
then
wp @development db reset --yes
wp @production db export - > sql-dump-production.sql
wp @development db import sql-dump-production.sql
wp @development search-replace https://example.com https://example.dev
else
exit 0
fi
@davemac
davemac / functions.php
Created January 3, 2017 06:04 — forked from kontikidigital/functions.php
WooCommerce: Change Select Options Button Text for variable products
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
/**
* custom_woocommerce_template_loop_add_to_cart
*/
function custom_woocommerce_product_add_to_cart_text() {
global $product;
$product_type = $product->product_type;
switch ( $product_type ) {
@davemac
davemac / umcp.php
Created November 27, 2016 07:35
WP upload media and create post using media as featured image
add_action('add_attachment', 'create_post');
function create_post( $attach_ID ) {
$attachment = get_post( $attach_ID );
$my_post_data = array(
'post_title' => $attachment->post_title,
'post_type' => 'dmc-photo',
'post_category' => array('0'),
'post_status' => 'publish'
@davemac
davemac / quotes.sh
Created October 19, 2016 08:09 — forked from SahilC/quotes.sh
A bash script to give you a random quote everytime you open your terminal. Add the following lines to your bashrc.
# font color : green
color='\e[0;32m'
# font color : white
NC='\e[0m'
getquote(){
num_online_quotes=9999
rand_online=$[ ( $RANDOM % $num_online_quotes ) + 1 ]
quote=$(wget -q -O - "http://www.quotationspage.com/quote/$rand_online.html" |
@davemac
davemac / pushstage
Last active November 15, 2017 05:29
wp-cli alias to push a local WP database to a staging site
# wp-cli alias to push a local WP database to a staging site
pushstage() {
START=$(date +%s)
# make a backup of the current local database
# get current directory name, used for database and URL
current=${PWD##*/}
wp db export $current.sql
# rsync the local database to staging site
rsync $current.sql $current-s:~/
# get the staging site URL for search replace
@davemac
davemac / dnsmasq_setup_osx.md
Created October 3, 2016 10:47 — forked from eloypnd/dnsmasq_setup_osx.md
wildcard DNS record on OS X in localhost development with dnsmasq

wildcard DNS in localhost development

$ brew install dnsmasq
   ...
$ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
  • edit /usr/local/etc/dnsmasq.conf
address=/local/127.0.0.1
@davemac
davemac / css-rating-stars.markdown
Created September 21, 2016 07:15
CSS Rating Stars