Skip to content

Instantly share code, notes, and snippets.

View techb's full-sized avatar

K.B. Carte techb

View GitHub Profile
// Yoink: https://www.javascripttutorial.net/web-apis/javascript-formdata/
const btn = document.querySelector('#submit-btn-id');
const form = document.querySelector('#my-form-id');
btn.addEventListener('click', (e) => {
// prevent the form from submitting
// or uncomment the debugger statment below for a breakpoint
// if needing to also send the data for testing
e.preventDefault();
@techb
techb / functions.php
Last active June 21, 2022 14:27
Disable WordPress search
<?php
// Yoink: https://www.wpbeginner.com/wp-tutorials/how-to-disable-the-search-feature-in-wordpress/
// Tested on WordPress: 5.9.3
// PHP: 8.0
/*
Instead of going to a search page, show 404 instead
*/
function wpb_filter_query( $query, $error = true ) {
if ( is_search() ) {
@techb
techb / GravityForms_Disable_AnchorScroll.md
Created May 3, 2022 20:52
Gravity Forms stop scrolling on multi-page ajax forms

When using a gravity form (multi-page, ajax) as a sticky modal for the bottom of the page, the generated anchor tag used to scroll interfears with the page scrolling.

The effect is when the user clicks the next button, the new page loads via ajax in the modal, but the gf js is trying to scroll to the top where the generated anchor tag is. But that's at the bottom of the page, so the page will auto scroll trying to keep up.

We can disable this behaviour with hooks. Add this to your themes function.php

Global disable add_filter( 'gform_confirmation_anchor', '__return_false' );

@techb
techb / template-home.php
Created April 26, 2022 16:01
WordPress Frontpage blog list pagination. How to use pagination with WP_Query.
<?php
/**
* Template Name: Homepage
*/
get_header();
// since this is the Front-Page we need to use "page" instead of "paged"
$paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
$args = array(
@techb
techb / zip2city.py
Created January 7, 2022 21:00
gets the cites associated with the given zipcode
# requires uszipcode
# $ pip install uszipcode
# zip.csv is a list of only zipcodes, one per each line
from sqlalchemy.sql.operators import op
from uszipcode import SearchEngine
from pprint import pprint
rtn = []
zips = []
@techb
techb / export_wp_db.php
Last active March 16, 2022 17:07
Exports wp db using wpcli. Found not working for CloudWays, something to do with file paths?
<?php
function validate_export( $filename ){
$ext = explode(".", $filename);
if( $ext[1] && $ext[1] != "sql" ){
return false;
}
if( $ext[2] && $ext[2] != "gz" ){
return false;
}
@techb
techb / add-admin-column.php
Last active February 15, 2022 23:33
wordpress function to add a new column to admin list view of selected post-type and field
<?php
// yoink: https://wordpress.stackexchange.com/a/379641
// add this to functions.php
function add_admin_column($column_title, $post_type, $cb){
// Column Header
add_filter( 'manage_' . $post_type . '_posts_columns', function($columns) use ($column_title) {
$columns[ sanitize_title($column_title) ] = $column_title;
return $columns;
} );
ssh -L 33666:127.0.0.1:3306 <USER>@<IP OR DOMAIN>