Skip to content

Instantly share code, notes, and snippets.

View jondcampbell's full-sized avatar

Jon Campbell jondcampbell

View GitHub Profile
@jondcampbell
jondcampbell / controller.php
Created October 9, 2015 23:08
query a prices table, finding me the companies with the most products. uses laravel and db query builder. grouping and ordering
$companies = DB::table('prices')
->select(DB::raw('company_id, COUNT(*) as total_products'))
->groupBy('company_id')
->orderBy('total_products', 'desc')
->get();
@jondcampbell
jondcampbell / cmb2setup.php
Created January 4, 2016 23:01
CMB2 File List: Don't show media from other posts. The key is the query_args that tell the media uploader to only show the resources uploaded to post 99999999999 (which I hope never exists).
$this->cmb_form->add_field( array(
'name' => 'Resource File List',
'desc' => '',
'id' => $this->cmb_prefix . 'resource_files',
'type' => 'file_list',
// 'preview_size' => array( 100, 100 ), // Default: array( 50, 50 )
'attributes' => array(
'required' => true, // Will be required only if visible.
'data-conditional-id' => $this->cmb_prefix . 'resource_type',
'data-conditional-value' => 'files',
@jondcampbell
jondcampbell / template.php
Created February 16, 2016 18:48
check if an acf link field value is for our current site or an external link
<?php
$our_parsed_url = parse_url( site_url() );
$link_parsed_url = parse_url( get_sub_field( 'link' ) );
if ( $our_parsed_url['host'] === $link_parsed_url['host'] ) :
$external_link = false;
else :
$external_link = true;
endif;
?>
@jondcampbell
jondcampbell / functions.php
Created July 15, 2016 18:56
updating data on wp all import save
add_action( 'pmxi_saved_post', 'sgc_post_saved', 10, 1 );
function sgc_post_saved( $post_id ) {
// We only want to run this on import of course members
if ( 'course-members' === get_post_type( $post_id ) ) :
// Perform proper date formatting on our date of birth field, and passport dates
update_date_value_of_post( $post_id, 'personal_date_of_birth' );
update_date_value_of_post( $post_id, 'travel_passport_date_of_issue' );
@jondcampbell
jondcampbell / class.php
Last active December 13, 2016 22:35
dont use this, scratch example
// The Field
$this->cmb_resource_form->add_field( array(
'name' => 'Seasons',
'desc' => '',
'id' => $this->cmb_prefix . 'seasons',
'taxonomy' => 'season', //Enter Taxonomy Slug
'type' => 'taxonomy_multicheck',
// Optional:
'options' => array(
'no_terms_text' => 'Sorry, no seasons could be found.' // Change default text. Default: "No terms"
@jondcampbell
jondcampbell / functions.php
Created December 22, 2016 19:20
messy mobile menu combo
function dpcc_add_slide_out_left_navigation(){
ob_start();
?>
<div id="left-nav">
<?php if ( is_user_logged_in() ) { ?>
<div class="dpcc-more-slide-out-left-menu">
<?php wp_nav_menu( array( 'theme_location' => 'secondary' ) ); ?>
@jondcampbell
jondcampbell / single-quiz.php
Created January 19, 2017 22:46
Test how random a Sensei quiz is
<?php
$questions_wanted = 2000;
$questions_got = 0;
$all_questions = [];
while($questions_got < $questions_wanted){
$questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() );
if( count( $questions ) > 0 ){
foreach($questions as $question):
array_push($all_questions, $question->ID);
public function prepare() {
$data = [];
$total = 0;
// Get the regions
$regions = get_terms( array(
'taxonomy' => 'naspd_company_region',
'hide_empty' => true,
) );
foreach ( $regions as $region ) {
@jondcampbell
jondcampbell / cache-functions.php
Created April 5, 2018 20:53
Clear some WP Super Cache files when any post is saved
<?php
/**
* Functionality for managing WP Super Cache
*/
/**
* On post save
*
@jondcampbell
jondcampbell / email-order-details.php
Created April 10, 2018 22:55
Adding Moneris credit card type to woocommerce order emails
<?php
/*
* This would fit into yourtheme/woocommerce/emails/email-order-details.php and replace the existing loop of totals in there.
*/
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $key => $total ) {
$i++;