Skip to content

Instantly share code, notes, and snippets.

View ewistrand's full-sized avatar
🦸‍♂️

Eric Wistrand ewistrand

🦸‍♂️
  • Truly Free
  • Traverse City Michigan
View GitHub Profile
@ewistrand
ewistrand / loop-paged-response.py
Created October 10, 2023 16:30
Loop through paged request with Python
import requests
resp = requests.get('https://url.com/api/endpoint').json()
data = resp['data']
while resp['next_page_url']:
resp = requests.get(resp['next_page_url']).json()
data.extend(resp['data'])
@ewistrand
ewistrand / wp-custom-paginated-loop.php
Created November 19, 2015 14:49
Custom Wordpress loop with pagination
<?php
/**
* Create post loop query
*/
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'orderby' => 'menu_order',
'order' => 'ASC',
'showposts' => 3,
@ewistrand
ewistrand / wp-tags-to-search.php
Created February 25, 2016 13:21
Add tags to wordpress search
<?php
// ADD Tags To SEARCH
function my_smart_search( $search, &$wp_query ) {
global $wpdb;
if ( empty( $search ))
return $search;
$terms = $wp_query->query_vars[ 's' ];
$exploded = explode( ' ', $terms );
@ewistrand
ewistrand / wp-extract-shortcode.php
Created November 19, 2015 14:08
WP Extract Shortcode from the_content
<?php
/**
* Use in loop or single, has to access post_content
*/
$pattern = get_shortcode_regex();
preg_match('/'.$pattern.'/s', $post->post_content, $matches);
if (is_array($matches) && $matches[2] == 'smart_track_player') {
$shortcode = $matches[0];
echo do_shortcode($shortcode);
}
@ewistrand
ewistrand / nl2p.php
Last active February 17, 2020 20:12
Turn line breaks into paragraph tags
if(! function_exists('nl2p')) {
function nl2p($str) {
$arr = explode("\n", $str);
$out = '';
for($i = 0; $i < count($arr); $i++) {
if(strlen(trim($arr[$i])) > 0)
$out .= '<p>' .trim($arr[$i]) . '</p>';
}
@ewistrand
ewistrand / split_name.php
Last active February 17, 2020 20:11
Split Name Input into First, Midldle and Last names
if(! function_exists('split_name')) {
function split_name($name) {
$parts = array();
while ( strlen( trim($name)) > 0 ) {
$name = trim($name);
$string = preg_replace('#.*\s([\w-]*)$#', '$1', $name);
$parts[] = $string;
$name = trim( preg_replace('#'.$string.'#', '', $name ) );
}
@ewistrand
ewistrand / paginateCollection.php
Last active February 17, 2020 20:06
Helper function to Paginate a Laravel Collections.
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
if(! function_exists('paginate'))
{
function paginate($items, $perPage = 15, $page = null)
{
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
$items = $items instanceof Collection ? $items : Collection::make($items);
@ewistrand
ewistrand / clear-gitignore.txt
Created July 19, 2019 19:08 — forked from ainsofs/gist:2b80771a5582b7528d9e
Clear .gitignore cache
# remove specific file from git cache
git rm --cached filename
# remove all files from git cache
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
@ewistrand
ewistrand / wp-breadcrumbs.php
Created November 25, 2015 21:09
Wordpress Breadcrumbs
function the_breadcrumb() {
global $post;
echo '<ul id="crumbs">';
if (!is_home()) {
echo '<li><a href="';
echo get_option('home');
echo '">';
echo 'Home';
echo "</a></li>";
if (is_category() || is_single()) {
@ewistrand
ewistrand / woo-disable-payment-require.php
Created November 23, 2015 21:48
Woocommerce disable requirement of payment
<?php
// woocommerce cart disable requirement of payment
add_filter('woocommerce_cart_needs_payment', '__return_false');
?>