Skip to content

Instantly share code, notes, and snippets.

View traversal's full-sized avatar

Travis Hensgen traversal

  • Traversal
  • Melbourne, Australia
View GitHub Profile
@traversal
traversal / gist:10694065
Created April 15, 2014 01:12
MasterPress RSS Download Example
<?php
// Assumes MasterPress has been used to setup a "download" file type with a "details" field set and
// "file" field within that set.
// Place this code in functions.php
function feed_item() {
global $wf;
echo $wf->the->details->file->enclosure();
<?php
$stores_by_city = $wf->stores("orderby=title&order=ASC")->group_by("address.city");
?>
<?php foreach ($stores_by_city as $city => $stores) : ?>
<h2><?= $city ?></h2>
<?php foreach ($stores as $store) : ?>
@traversal
traversal / gist:6684b050d013b68e8c6c
Created October 8, 2014 03:39
Getting an array of field set names
<?php
// assuming you have a post type "logo", here is the code to get an array of set names for that type.
<?php
echo "<h2>Logo Field Sets</h2>";
global $meow_provider;
@traversal
traversal / gist:f32bf2abc414cad855a8
Created October 9, 2014 21:56
Checkbox List Labels
<?php
// Add this method to MPFT_CheckboxList
// this returns an associative array of the selections, with keys being the checkbox values, values being the labels.
function selections() {
if (!isset($this->_tv)) {
$options = $this->field()->info->type_options;
@traversal
traversal / gist:20cfb74a164a4a302646
Created October 20, 2014 11:25
Production Dates
<ul>
<?php foreach ($wf->type("production")->by("production_deadline_fields.deadline_date", "DESC") as $production) : ?>
<li>
<h2>Production: <?= $production->title ?></h2>
<p>
Date: <?= $production->production_deadline_fields->deadline_date ?>
</p>
</li>
<?php endforeach; ?>
</ul>
@traversal
traversal / gist:6a13e7786d168d7588db
Created November 5, 2014 06:24
Dedupe Workaround
<?php
// -- in functions.php
// --- Suppose you want to dedupe by a "first_name" field in a "bio" set
class MY_Post extends MEOW_Post {
function bio_firstname() {
return $this->bio->first_name();
<?php
// place this inside functions.php
function my_function() {
global $wf;
// should be able to loop over post types, for example
foreach ( $wf->post_types as $pt ) {
@traversal
traversal / gist:ed1eb9a033a51e44b35d
Last active August 29, 2015 14:12
Edit attachment
<?php
function my_update_media($object_id, $object_type) {
global $wf;
if ($object_type == "post") {
$post = $wf->post($object_id);
<!DOCTYPE html>
<html>
<head>
<?php
// Requires gmaps.js from GitHub:
// http://hpneo.github.io/gmaps/
@traversal
traversal / gist:e57d96397172ca25c088
Created January 28, 2015 03:38
Force Template Change
// Add this to functions.php
function mp_template_change() {
echo "<script>jQuery( function($) { $('#mp-attributes select[name=page_template]').change(); } );</script>";
}
add_filter("admin_head", "mp_template_change");