Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View n8finch's full-sized avatar

Nate Finch n8finch

View GitHub Profile
<?php
/**
* Plugin Name: TOPTAL WP-CLI Commands
* Version: 0.1
* Plugin URI: https://n8finch.com/
* Description: Some rando wp-cli commands to make life easier...
* Author: Nate Finch
* Author URI: https://n8finch.com/
* Text Domain: toptal-wpcli
* Domain Path: /languages/
@n8finch
n8finch / replace_concat.sql
Created May 10, 2017 06:04
some incomplete SQL scripts.
SELECT
wp_redirection_items.*,
wp_redirection_groups.position AS group_pos
FROM wp_redirection_items
INNER JOIN wp_redirection_groups ON
wp_redirection_groups.id=wp_redirection_items.group_id
AND wp_redirection_groups.status='enabled'
AND wp_redirection_groups.module_id RLIKE 'd'
WHERE (wp_redirection_items.regex=1 OR wp_redirection_items.url RLIKE '\/$')
@n8finch
n8finch / insert_join_redirection.sql
Created May 10, 2017 06:02
the following SQL would duplicate the redirects that end with '/', making a copy without a slash.
INSERT INTO wp_redirection_items(
`url`,
`regex`,
`position`,
`last_count`,
`last_access`,
`group_id`,
`status`,
`action_type`,
`action_code`,
@n8finch
n8finch / sql_query_examples.sql
Last active April 20, 2017 06:47
SQL query samples.
SELECT meta_key, meta_value
FROM wp_postmeta
WHERE meta_key = "issue_id"
But I need to only do posts with a category of
UPDATE wp_postmeta SET meta_value = '0' WHERE meta_value = '1';
@n8finch
n8finch / update_in_sql.sql
Created March 20, 2017 13:06
UPDATE in SQL
UPDATE wp_postmeta AS a
JOIN wp_term_relationships AS b
ON a.post_id=b.object_id
SET meta_value=0
WHERE term_taxonomy_id = 9 AND meta_key = 'issue_id' AND meta_value != 0;
@n8finch
n8finch / select_in_sql.sql
Created March 20, 2017 13:05
SELECT in SQL
SELECT wp_term_relationships.term_taxonomy_id, wp_term_relationships.object_id, wp_postmeta.post_id, wp_postmeta.meta_key, wp_postmeta.meta_value
FROM wp_term_relationships
JOIN wp_postmeta
ON wp_postmeta.post_id=wp_term_relationships.object_id
WHERE term_taxonomy_id = 9 AND meta_key = 'issue_id' AND meta_value != 0;
@n8finch
n8finch / simple_sql_select.sql
Created March 20, 2017 13:05
simp SQL select
SELECT object_id, term_taxonomy_id
FROM wp_term_relationships
WHERE term_taxonomy_id = 9;
@n8finch
n8finch / check_types_in_admin_ajax_console.php
Created January 6, 2017 07:47
Quick type checking in php, outputs to browser console in admin ajax
// Quick type checking in php, outputs to browser console in admin ajax
echo 'Type: '. gettype($bc_exists) . "\n";
echo 'Null: '. is_null($bc_exists) . "\n";
echo 'Array: '. is_array($bc_exists). "\n";
echo 'isset: '. is_array($bc_exists). "\n";
echo 'Empty: '. empty($bc_exists). "\n";
echo 'Boolean: '. is_bool($bc_exists). "\n";
echo 'String: '. is_string($bc_exists). "\n";
echo 'Object: '. is_object($bc_exists). "\n";
@n8finch
n8finch / jQuery-UI-Dialog-Popup-Responsive-with-JavaScript.js
Created November 21, 2016 03:51
Make jQuery UI's Dialog Popup Responsive with JavaScript
//Get Window Screen Width
var screenWidth, screenHeight, dialogWidth, dialogHeight, isDesktop;
screenWidth = window.screen.width;
screenHeight = window.screen.height;
if ( screenWidth < 500 ) {
dialogWidth = screenWidth * .95;
dialogHeight = screenHeight * .95;
@n8finch
n8finch / add-base-location-provider-to-wp-head.php
Created September 19, 2016 04:00
add-base-location-provider-to-wp-head.php
//*Add the base "/" to the head for pretty routing.
add_action( 'wp_head', __NAMESPACE__ . '\add_base_location_provider_to_wp_head' );
function add_base_location_provider_to_wp_head() {
echo '<base href="/">';
}