Skip to content

Instantly share code, notes, and snippets.

View stevenspads's full-sized avatar

Steven stevenspads

View GitHub Profile
@stevenspads
stevenspads / WordPress email change disabler
Created July 6, 2016 18:11
WordPress - Disable user notification emails when changing a user's email address
add_filter( 'send_email_change_email', '__return_false' );
@stevenspads
stevenspads / WordPress Custom Post Type Creator
Created July 6, 2016 18:14
WordPress - Creating a Custom Post Type
add_action('init', 'register_cpt', 1); // Set priority to avoid plugin conflicts
function register_cpt() {
$singular = "_cpt_name_";
$plural = "_cpt_name_plural_";
$labels = array(
'name' => _x($plural, 'post type general name'),
'singular_name' => _x($singular, 'post type singular name'),
'add_new' => _x('Add New', $singular),
'add_new_item' => __('Add New '.$singular),
@stevenspads
stevenspads / WordPress Get Monthly Archives
Created July 7, 2016 15:43
List monthly archives using Bootstrap styling
<ul class='list-group'>
<?php
$args = array(
'type' => 'monthly',
'limit' => '',
'format' => 'custom',
'before' => '<li class="list-group-item">',
'after' => '</li>',
'show_post_count' => false,
'echo' => 1,
@stevenspads
stevenspads / WordPress display post archives by Year and Month
Last active October 11, 2019 05:28
Get WordPress post archives by Year and then by each Month per year. Display the results with Bootstrap styling.
<?php
global $wpdb;
$limit = 0;
$year_prev = null;
$months = $wpdb->get_results("SELECT DISTINCT MONTH( post_date ) AS month , YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = 'publish' and post_date <= now( ) and post_type = 'post' GROUP BY month , year ORDER BY post_date DESC");
foreach($months as $month) :
$year_current = $month->year;
@stevenspads
stevenspads / WordPress Archive page loop
Created July 7, 2016 16:05
WordPress basic Archive page loop
<?php
if ( have_posts() ) : ?>
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="archive-description">', '</div>' );
?>
</header>
@stevenspads
stevenspads / Installing Intervention Image in Laravel 5
Created July 8, 2016 03:00
Installing Intervention Image in Laravel 5
Installing Intervention Image in Laravel 5
1. Find the composer.json in your root directory and add "intervention/image": "2.*" in the require section:
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"intervention/image": "2.*"
},
@stevenspads
stevenspads / WordPress ordering WP_QUERY results by several meta keys
Created July 9, 2016 05:27
Ordering WP_QUERY results by several meta keys in WordPress
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'games',
'author' => $user_id,
'meta_query' => array(
'relation' => 'AND',
'game_date' => array(
'key' => 'game_date',
@stevenspads
stevenspads / WordPress WP_QUERY Meta Key Sorter
Created July 9, 2016 05:34
WordPress Sorting WP_QUERY results by multiple meta keys
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'product',
'posts_per_page' => POSTS_PER_PAGE,
'paged' => $paged,
'meta_query' => array(
'relation' => 'AND',
'price' => array(
@stevenspads
stevenspads / Merge multiple WP_QUERY objects into one
Created July 12, 2016 19:34
Merging WP_QUERY objects in WordPress
//Your original 2 WP_Query results:
$query1 = new WP_Query($args_for_query1);
$query2 = new WP_Query($args_for_query2);
//Create a new WP_Query object to hold the joining of the 2 originals:
$joined_query = new WP_Query();
$joined_query->posts = array_merge( $query1->posts, $query2->posts );
// how to write content to a file
$content = 'File content ...';
Storage::put( 'myfile.txt', $content );
// how to read content from a file
$content = Storage::get( 'myfile.txt' );
// how to delete a file
Storage::delete( 'myfile.txt' );