Skip to content

Instantly share code, notes, and snippets.

<?php
$args = array(
'post_type' => 'services'
);
$the_query = new WP_query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post() ;?>
@ericjuden
ericjuden / jquery-image-resize.js
Created March 3, 2014 21:16
JQuery Image Resize
$(document).ready(function() {
$('.story-small img').each(function() {
var maxWidth = 100; // Max width for the image
var maxHeight = 100; // Max height for the image
var ratio = 0; // Used for aspect ratio
var width = $(this).width(); // Current image width
var height = $(this).height(); // Current image height
// Check if the current width is larger than the max
if(width > maxWidth){
@ericjuden
ericjuden / wordpress-options-json.php
Last active June 30, 2022 12:33
WordPress Options Class with Support for storing and retrieving JSON
<?php
class My_Plugin_Options {
var $options;
var $option_name;
var $is_site_option; // Are we using Multisite and saving to global options?
function My_Plugin_Options($option_name, $is_site_options = false){
$this->option_name = $option_name;
$this->is_site_option = $is_site_options;
if($this->is_site_option){
@ericjuden
ericjuden / Microsoft.PowerShell_profile.ps1
Created January 28, 2014 22:50
Search for .ps1 files in a given directory
# Search for .ps1 files in a given directory
Get-ChildItem C:\Code\powershell -Include *.ps1 -Recurse -Force | % { . $_.FullName }
@ericjuden
ericjuden / list-blogs-alpha.php
Created May 15, 2013 12:56
WordPress Multisite: List Blogs Alphabetically
<?php if(is_front_page()){ ?>
<h1>Blog Directory</h1>
<?php
global $wpdb;
$aBlogs = array();
$query = "SELECT blog_id FROM " . $wpdb->base_prefix . "blogs WHERE spam != '1' AND archived != '1' AND deleted != '1' AND public = '1' AND blog_id != '1' ORDER BY path";
$blogs = $wpdb->get_results($query);
@ericjuden
ericjuden / list-blogs.php
Created May 15, 2013 11:55
WordPress Multisite: List Blogs
<?php if(is_front_page()){ ?>
<h1>Blog Directory</h1>
<?php
global $wpdb;
$query = "SELECT blog_id FROM " . $wpdb->base_prefix . "blogs WHERE spam != '1' AND archived != '1' AND deleted != '1' AND public = '1' AND blog_id != '1' ORDER BY path";
$blogs = $wpdb->get_results($query);
echo '<ul>';
@ericjuden
ericjuden / default-sections.css
Last active December 16, 2015 15:09
Default Starter Stylesheet
/********************************************************
* Main Body Styles
********************************************************/
/********************************************************
* Header Styles
********************************************************/
@ericjuden
ericjuden / create-sample-tables.php
Last active December 14, 2015 19:29
WordPress Custom Tables
<?php
/*
Plugin Name: Create Sample Tables Plugin
Plugin URI: http://ericjuden.com
Description: Create some dummy tables
Version: 1.0
Author: ericjuden
Author URI: http://ericjuden.com
*/
@ericjuden
ericjuden / create.php
Last active April 3, 2024 12:18
WordPress CRUD
<?php
// Create a new record in a table
global $wpdb;
// data to be added
$data = array(
'post_title' => __('This is a test'),
'post_content' => __('This is really long text'),
'post_status' => __('draft')
@ericjuden
ericjuden / prepare-sql.php
Last active December 12, 2015 09:58
WordPress St. Louis Developers Meetup: Security Best Practices
<?php
global $wpdb;
// Clean SQL before running
$sql = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE status = %s AND post_type = %s', 'publish', 'page');
// Return results
$results = $wpdb->get_results($sql);
?>