Skip to content

Instantly share code, notes, and snippets.

Avatar

Craig Grella craiggrella

View GitHub Profile
@craiggrella
craiggrella / string query in staged donation for nationbuilder
Last active Jun 6, 2016
Adds ability to collect donation amounts in string query passed in URL. Great for adding auto amounts in buttons and text inside emails.
View string query in staged donation for nationbuilder
// Added by CraigGrella.com for pinning amount to string query
// Used for creating buttons in emails with links for specific dollar amounts
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
@craiggrella
craiggrella / Custom Meta Query with Post Object in Advanced Custom Fields
Last active Aug 29, 2015
Custom query with staff list from advanced custom fields meta query
View Custom Meta Query with Post Object in Advanced Custom Fields
// Add Staff Picks below Staff Member
add_action( 'genesis_entry_content', 'os_add_recent_staff_picks' );
function os_add_recent_staff_picks() {
// Custom Loop Calling Staff Picks from Author Currently being viewed
$staffname = get_the_title();
// New Query for staff picks matching author name
$pick_args = array(
'posts_per_page' => 3,
View Custom ACF Query for Staff Picks
// Custom Loop Calling Staff Picks from Author Currently being viewed
$picks = get_posts(array(
'posts_per_page' => 3,
'post_type' => 'staffpicks',
'meta_query' => array(
array(
'key' => 'author', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
@craiggrella
craiggrella / page-support-questions.php
Last active Aug 29, 2015
Custom query to sort by category in genesis
View page-support-questions.php
add_action( 'genesis_entry_content', 'user_post_list' );
function user_post_list() {
if ( ! is_user_logged_in() ) :
echo 'You must be logged-in to view your submitted questions and answers.';
// wp_login_form();
else :
View Filter gforms woo commerce add on button
// filter the Gravity Forms button type
remove_filter('gform_submit_button_2', 'form_submit_button', 10, 2);
add_filter('gform_submit_button_2', 'form_submit_button', 10, 2);
function form_submit_button($button, $form){
return "<button type='submit' class='single_add_to_cart_button button alt gform_button' id='gform_submit_button_{$form["id"]}'>Donate Now</button>";
}
@craiggrella
craiggrella / Change Woo Add to Cart Text
Created Jul 6, 2014
Changes the add to cart text on woo commerce single products filtering by product category.
View Change Woo Add to Cart Text
/* CHANGE ADD TO CART BUTTON TEXT ON A PER PRODUCT BASIS
**********************************************************/
add_filter('single_add_to_cart_text', 'woo_custom_cart_button_text');
function woo_custom_cart_button_text() {
if ( is_singular('product') ) {
global $post;
@craiggrella
craiggrella / post-sort-order-by-meta.php
Last active Aug 29, 2015
Change Post Sort Order by Meta Key in WordPress
View post-sort-order-by-meta.php
// change sort order of posts based on meta
function change_order_for_post_archive( $query ) {
//only show future events and events in the last 24hours
if ( $query->is_main_query() && is_post_type_archive('attorney') ) {
$query->set( 'meta_key', 'ecpt_position' );
$query->set( 'orderby', 'meta_value' );
$query->set( 'order', 'ASC' );
}
@craiggrella
craiggrella / Genesis Woo Cart Button Text.php
Last active Aug 29, 2015
Change Add to Cart Text on WooCommerce
View Genesis Woo Cart Button Text.php
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' ); // < 2.1
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 +
function woo_custom_cart_button_text() {
return __( 'Buy Product', 'textdomain' );
}
View WooCommerce Hide Product Fields on Virtual product
<?php
add_filter( 'woocommerce_checkout_fields' , 'woo_remove_billing_checkout_fields' );
/**
* Remove unwanted checkout fields
*
* @return $fields array
*/
function woo_remove_billing_checkout_fields( $fields ) {