Skip to content

Instantly share code, notes, and snippets.

View michaelschofield's full-sized avatar

Michael Schofield michaelschofield

View GitHub Profile
@michaelschofield
michaelschofield / taxonomy.php
Created April 8, 2015 06:03
Should be in advwp_event_manager/public/templates/
<?php
/**
* Used to display event taxonomy pages.
*/
get_header(); ?>
<section id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
/**
* Plugin Name: ADVWP Library Event Manager
* Plugin URI: http://classes.alaeditions.org/course/view.php?id=225
* Description: A simple library event management system.
* Version: 0.4.0
* Author: Your Name!
* Author URI: http://www.yourwebsite.com
*/
@michaelschofield
michaelschofield / wp_query_by_custom_fields_for_taxonomies.php
Created April 8, 2015 04:45
This is an example of a taxonomy-archive WP_Query() ordered by two [or more] custom fields. Sorry, this gist is a little out of context, as it is embedded within a bunch of other course material. Still hopefully useful though!
<?php
// The query-by-custom-fields for a taxonomy archive
// is similar that of the post type archive, except we need
// to use "get_queried_object()" so that WordPress knows which
// term to use to match posts.
function advwp_edit_event_order( $orderby ) {
// First sort by start date, but then internally sort
// by start time - starting with the earliest.
<?php
// The function to create a taxonomy archive within a
// plugin is nearly identical to creating the post type
// archive, except instead of using is_post_type_archive()
// we use is_tax().
function advwp_create_series_template( $archive ) {
global $post;
if ( is_tax( 'series' ) ) {
return plugin_dir_path( __FILE__ ) . 'public/templates/taxonomy-series.php';
function advwp_edit_event_order( $orderby ) {
// First sort by start date, but then internally sort
// by start time - starting with the earliest.
return 'mt1.meta_value, mt2.meta_value ASC';
}
$args = array(
// fetch only "events""
'post_type' => 'event',
<?php
$args_version_1 = array(
// The name of the custom field
'meta_key' => 'color',
// A specific value we might optionally look for
'meta_value' => 'blue',
@michaelschofield
michaelschofield / archive.php
Last active August 29, 2015 14:18
The Twentyfifteen archive.php file
<?php
/**
* The template for displaying archive pages
*/
get_header(); ?>
<section id="primary" class="content-area">
<main id="main" class="site-main" role="main">
@michaelschofield
michaelschofield / post_type_archive_template_in_plugin.php
Created April 7, 2015 03:17
An example of how to create a post type archive template in a plugin
/* You can create a post-type archive in a WordPress Theme
* by creating the file archive-name_of_post_type.php. Sometimes,
* in the interest of modularity, we will want to create and use
* a template bundled with the plugin.
* Further examples can be found at
* https://codex.wordpress.org/Plugin_API/Filter_Reference/archive_template
*/
function advwp_create_archive_event_view( $archive ) {
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
<?php
/* Here is the standard loop preceded by the WordPress
* class WP_Query(), which let us alter the parameters of
* the query WordPress makes to retrieve posts. In this
* example, the "arguments" (args) we make will do be
* for all posts that are "Events". I think you'll find it
* pretty straightforward!
*/