Skip to content

Instantly share code, notes, and snippets.

Avatar

Nate Finch n8finch

View GitHub Profile
@n8finch
n8finch / sql_query_examples.sql
Last active Apr 20, 2017
SQL query samples.
View sql_query_examples.sql
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';
View update_in_sql.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;
View select_in_sql.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;
View simple_sql_select.sql
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 Jan 6, 2017
Quick type checking in php, outputs to browser console in admin ajax
View check_types_in_admin_ajax_console.php
// 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 Nov 21, 2016
Make jQuery UI's Dialog Popup Responsive with JavaScript
View jQuery-UI-Dialog-Popup-Responsive-with-JavaScript.js
//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 Sep 19, 2016
add-base-location-provider-to-wp-head.php
View 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="/">';
}
@n8finch
n8finch / filter-nav-menu-items-genesis-angular-gulp.php
Created Sep 19, 2016
filter-nav-menu-items-genesis-angular-gulp
View filter-nav-menu-items-genesis-angular-gulp.php
add_filter( 'wp_setup_nav_menu_item', __NAMESPACE__ . '\filter_nav_menu_items', 1 );
function filter_nav_menu_items( $menu ) {
$post_type = ( $menu->object ); //gets post type
//if post type is a page, then create a new URL
if ( $post_type === 'page' ) {
$menu_url = $menu->url;
$new_url = '/pages' . str_replace( 'https://n8finch.dev/', '/', $menu_url );
$menu->url = $new_url;
}
@n8finch
n8finch / page-view-genesis-angular-gulp.html
Created Sep 19, 2016
page-view-genesis-angular-gulp.html
View page-view-genesis-angular-gulp.html
<article class="single-post post type-post status-publish format-standard has-post-thumbnail entry"
ng-controller="pageView">
<header class="entry-header">
<h2 class="entry-title">{{post.title.rendered}}</h2>
</header>
<img class="attachment-post-image size-post-image wp-post-image" ng-src="{{post.featured_image_src}}"/>
<div class="entry-content">
<p ng-bind-html="post.content.rendered | to_trusted"></p>
</div>
<footer class="entry-footer">
@n8finch
n8finch / pageView-controller-genesis-angular-gulp.js
Created Sep 19, 2016
pageView-controller-genesis-angular-gulp.js
View pageView-controller-genesis-angular-gulp.js
.controller('pageView', ['$scope', '$http', '$stateParams', function ($scope, $http, $stateParams) {
console.log('pageView running');
$http({
url: 'https://n8finch.dev/wp-json/wp/v2/pages?filter[name]=' + $stateParams.slug,
cache: true
}).success(function (res) {
$scope.post = res[0];
});
}])