Skip to content

Instantly share code, notes, and snippets.

View craiggrella's full-sized avatar

Craig Grella craiggrella

View GitHub Profile
@craiggrella
craiggrella / string query in staged donation for nationbuilder
Last active June 6, 2016 11:29
Adds ability to collect donation amounts in string query passed in URL. Great for adding auto amounts in buttons and text inside emails.
// 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 August 29, 2015 14:07
Custom query with staff list from advanced custom fields meta query
// 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,
// 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 August 29, 2015 14:07
Custom query to sort by category in genesis
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 :
// 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 July 6, 2014 04:59
Changes the add to cart text on woo commerce single products filtering by product category.
/* 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 August 29, 2015 14:02
Change Post Sort Order by Meta Key in WordPress
// 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 August 29, 2015 13:59
Change Add to Cart Text on WooCommerce
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' );
}
<?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 ) {