Skip to content

Instantly share code, notes, and snippets.

techslides / wp-sort.php
Last active Oct 29, 2017
Sort WordPress Posts by Modified Date using Query Param
View wp-sort.php
//put this into functions.php and add url param to homepage: sortby=updated
function custom_query_vars_filter($vars) {
$vars[] = 'sortby';
//$vars[] .= 'another';
return $vars;
add_filter( 'query_vars', 'custom_query_vars_filter' );
techslides / multiple-insert-on-duplicate-update.php
Created Jul 12, 2016
INSERT on duplicate update PHP function for WordPress multiple or batch operation
View multiple-insert-on-duplicate-update.php
//based on Wordpress Multiple Insert
function wp_insert_update_rows($row_arrays = array(), $wp_table_name) {
global $wpdb;
$wp_table_name = esc_sql($wp_table_name);
$update = "";
$query = "";
$query_columns = "";
$query. = "INSERT INTO {$wp_table_name} (";
techslides / formidable-inplace-callback.js
Last active Jun 14, 2016
Call a function after in-place edit loads a form
View formidable-inplace-callback.js
//change the formibdale.js file here:
//ADD THIS: call some function if it is defined
if (typeof inlineEditCallback == 'function') {
techslides / formidable-repeatable.php
Last active Jun 14, 2016
Create a repeatable section entry in Formidable Form
View formidable-repeatable.php
We know our form has ID 1
The name field has ID 5, the repeatable section has ID 10, and 2 fields in repeatabale section are ID 11 and ID 12
But, how do we know that form_id is 2 below?
$parent_form_id = 1;
$child_name = "John";
techslides / flatten.php
Created May 17, 2016
Flattening Arrays with PHP
View flatten.php
//Good Article:
$aa = array("first name"=>"john","last name"=>"smith","more data"=>array("age"=>"12","role"=>"manager"),"gender"=>"male");
//flatten with keys
$output = iterator_to_array(new RecursiveIteratorIterator(
new RecursiveArrayIterator($aa)), TRUE);
techslides / debug-wordpress-queries.php
Created Jan 15, 2016
Debug WP Queries. Include this file in functions.php and then add ?debug=sql to any WP URL
View debug-wordpress-queries.php
if ( !defined('SAVEQUERIES') && isset($_GET['debug']) && $_GET['debug'] == 'sql' )
define('SAVEQUERIES', true);
if ( !function_exists('dump') ) :
* dump()

Easy Twitter API OAuth 2 Access

  1. Go to your applications. Create a new one, and find the values in the Consumer Key and Consumer Secret fields.

  2. Use OAuth client information to produce an OAuth 2 access token:

    curl -i --user <consumer_key>:<consumer_secret> -X POST -d "grant_type=client_credentials"
techslides / edit.php
Last active Feb 3, 2019
Editing GravityForms Entries on The FrontEnd
View edit.php
//link on a page to edit an entry: <a href="">Edit</a>
techslides / image-to-dataurl.js
Created May 6, 2015
App Script as Image Proxy
View image-to-dataurl.js
function doGet(e) {
var url = decodeURIComponent(e.parameter.url);
try {
var response = UrlFetchApp.fetch(url);
} catch (e) {
return e.toString();
var type = response.getHeaders()['Content-Type'];
var b64 = Utilities.base64Encode(response.getContent());
var data = 'data:'+type+';base64,'+b64;
techslides / pinterest-pin.js
Created Apr 22, 2015
Pinterest Pin Image Script
View pinterest-pin.js
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
loadImages: true,
loadPlugins: true,
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
You can’t perform that action at this time.