Skip to content

Instantly share code, notes, and snippets.

View Viper007Bond's full-sized avatar
😎
Writing Code

Alex Mills Viper007Bond

😎
Writing Code
View GitHub Profile
@Viper007Bond
Viper007Bond / gist:10040166
Created April 7, 2014 19:53
Default WordPress to use 4 column galleries
<?php
add_filter( 'shortcode_atts_gallery', 'sheri_galleries_default_to_four_columns', 10, 3 );
function sheri_galleries_default_to_four_columns( $atts, $defaults, $raw_atts ) {
// Don't override manually-set number of columns
if ( ! empty( $raw_atts['columns'] ) ) {
return $atts;
}
@Viper007Bond
Viper007Bond / gist:797685e2ef6e75e7289f
Created March 28, 2015 21:19
Include pages in category archive pages
<?php
/**
* Copy paste the below code into your theme's functions.php file.
* You could add it to a plugin instead, but it's just easier to
* add it to your theme's functions.php. The only drawback to this
* is if you switch themes, this functionality will stop working.
*
* --Alex Mills
* Questions? Contact me: http://www.viper007bond.com/contact/
@Viper007Bond
Viper007Bond / example.php
Created September 30, 2011 00:14
Private post_status in a List_Table
<?php
class Your_Media_List_Table extends WP_Media_List_Table {
/* some stuff here */
// Adds a WHERE modify filter, calls parent version of prepare_items(), then removes filter
function prepare_items() {
add_filter( 'posts_where', array( &$this, 'modify_post_status_to_private' ) );
@Viper007Bond
Viper007Bond / gist:1297669
Created October 19, 2011 07:27
Determining if modifying the main query or not in WordPress
<?php
# See bigdawggi's comment below for a good combined example
// Pre-3.3
function cf_google_search_kill_wp_search( $where, $query ) {
global $wp_the_query;
if( ! is_admin() && $query->is_search() && $query === $wp_the_query ) {
$where = ' AND 1=0';
@Viper007Bond
Viper007Bond / gist:1325696
Created October 30, 2011 08:11
Limit results to post meta via URL
<?php
add_action( 'pre_get_posts', 'oomskaap_price_range_limiter' );
function oomskaap_price_range_limiter( $query ) {
// Only do something if both the start and end values are set in the URL
if ( empty( $_GET['pricestart'] ) || empty( $_GET['priceend'] ) )
return;
// Only modify the main query
@Viper007Bond
Viper007Bond / gist:1390918
Created November 24, 2011 08:51
My Sublime Text 2 Configuration Files
// File Settings - User
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"font_face": "Consolas", // Windows, you'll likely want default or something else
"font_size": 10,
//"spell_check": true,
@Viper007Bond
Viper007Bond / cli-db-upgrade.php
Created December 6, 2011 23:47
Updgrade the WordPress DB from the command line
<?php
# Stick this file in your wp-content folder
define( 'WP_INSTALLING', true );
require_once( dirname( __FILE__ ) . '/../wp-load.php' );
timer_start();
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
@Viper007Bond
Viper007Bond / add-another-category-to-posts.php
Created February 16, 2012 08:24
WordPress: Add Another Category To Posts
<?php
/**
* Takes posts that are in category A and also adds them to category B
*/
// Uncomment this to proceed
exit( "You need to edit the file and enter the hostname and category IDs.\n" );
// What blog? Asking for both for safety reasons.
@Viper007Bond
Viper007Bond / gist:1903147
Created February 24, 2012 19:27
Modify post_types searched
<?php
add_action( 'pre_get_posts', 'localtv_posts_and_pages_for_search' );
function localtv_posts_and_pages_for_search( $query ) {
if ( $query->is_main_query() && $query->is_search() )
$query->set( 'post_type', array( 'post', 'page' ) );
}
@Viper007Bond
Viper007Bond / gist:2054188
Created March 17, 2012 01:31
Float Parsing Function Tests
<?php
// floatvalue() ended up working best most of the time, with only a few exceptions
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$floatvals = array(
'1,337.01',
'1,337',
'1337.01',