Skip to content

Instantly share code, notes, and snippets.

@milesstewart88
milesstewart88 / MySQL - Having Clause
Last active December 18, 2015 22:59
Using the HAVING keyword
/*
* When creating alias' and temp tables
* can't use where so use the
* HAVING keyword
*/
SELECT
CONCAT(bill_first_name, ' ', bill_last_name) AS full_name,
COUNT(CONCAT(bill_first_name, ' ', bill_last_name)) AS amount,
MAX(ordered_on) as date, email
@milesstewart88
milesstewart88 / PHP - Function - Explode Multiple Params
Created July 12, 2013 17:06
PHP - Function - Explode Multiple Params
<?php
function explodeMeTwice ($param) {
$id_pieces = explode("&", $param);
$new_piece = array();
foreach ($id_pieces as $piece) {
$the_piece = explode("=", $piece);
$new_piece[$the_piece[0]] = $the_piece[1];
@milesstewart88
milesstewart88 / WordPress - Custom CPT Columns
Created July 28, 2013 01:49
Custom CPT Columns // manage_edit-{post_name}_columns. To add the custom fields to the admin columns
<?php
/*
* Orders - Custom Columns
*/
add_filter( 'manage_edit-orders_columns', 'my_edit_orders_columns' ) ;
function my_edit_orders_columns( $columns ) {
$columns = array(
@milesstewart88
milesstewart88 / WordPress - Custom field values in Custom Columns
Created July 28, 2013 16:31
Place the custom field values in the custom columns
/*
* Custom fields in custom admin columns
*/
add_action( 'manage_orders_posts_custom_column', 'my_manage_orders_columns', 10, 2 );
function my_manage_orders_columns( $column, $post_id ) {
global $post;
switch( $column ) {
add_action( 'admin_init', 'redirect_non_admin_users' );
/**
* Redirect non-admin users to home page
*
* This function is attached to the 'admin_init' action hook.
*/
function redirect_non_admin_users() {
if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
wp_redirect( home_url() );
exit;
/*
*
* Upload Image to ACF Field
* From Frontend
*
*/
//functions.php on theme folder
function my_update_attachment($f,$pid,$t='',$c='') {
// Company Logo Image field
$att = my_update_attachment('user_photo', $post_id);
update_field('{field_key}', $att['attach_id'], $post_id);
@milesstewart88
milesstewart88 / PHP - Arrays - Sort Multi Dimensional
Last active December 21, 2015 13:19
Sort a multi-dimensional array by a value - Just use the value's keys
function compare_distance($a,$b)
{
if($a["details"]["distance"] == $b["details"]["distance"]) return 0;
return ($a["details"]["distance"] > $b["details"]["distance"]) ? 1 : -1;
}
usort($the_array, 'compare_distance');
@milesstewart88
milesstewart88 / WordPress - Before Page Load
Created January 19, 2014 06:57
Action that runs before page is loaded
add_action( 'wp', 'the_function_name' );