Skip to content

Instantly share code, notes, and snippets.

if (!class_exists('SubHeading')) {
class SubHeading
{
var $name = 'SubHeading';
var $tag = 'subheading';
var $meta_key;
var $options = array();
function SubHeading()
{
if ($options = get_option($this->tag)) {
@ericpedia
ericpedia / gist:1085282
Created July 15, 2011 18:55
How to change this foreach into a normal loop that can use, e.g., the_title()?
// http://wordpress.stackexchange.com/questions/23088/how-to-change-a-custom-query-into-a-standard-loop
$totalposts = $wpdb->get_results($querystr, OBJECT);
$wp_query->request = $querystr . " LIMIT " . $ppp . " OFFSET " .$offset;
$results = $wpdb->get_results($wp_query->request, OBJECT);
foreach ($results as $result) { /* instead of this I want something that would work like while ( $the_query->have_posts() ) : $the_query->the_post(); */
$offset++;
$output .= '<a href="'.get_post_permalink($result->ID).'">' . $result->post_title . ' (' . $result->post_date . ')</a><br>';
@ericpedia
ericpedia / gist:1120331
Created August 2, 2011 14:45
how do I get the permalink of the first term
function hey_author_link() {
$terms = wp_get_object_terms( get_the_ID(), 'people' );
$term_permalink = get_term_link($terms[0]->slug, 'people');
return $term_permalink;
}
@ericpedia
ericpedia / gist:1122631
Created August 3, 2011 13:31
get top parents in wordpress
<?php
function get_term_top_most_parent($term_id, $taxonomy){
$parent = get_term_by( 'id', $term_id, $taxonomy);
while ($parent->parent != 0){
$parent = get_term_by( 'id', $term_id, $taxonomy);
}
return $parent;
}
// so once you have this function you can just loop over the results returned by wp_get_object_terms
@ericpedia
ericpedia / gist:1125575
Created August 4, 2011 16:30
Get top-most parent of a taxonomy term
<?php
/****************************************************
Get top-most parent of a taxonomy term
****************************************************/
function get_term_top_most_parent($term_id, $taxonomy){
$term = get_term_by( 'id', $term_id, $taxonomy);
<?php
//remove default metabox
//change TAXONOMY_NAME to your taxonomy name
function remove_post_custom_fields() {
remove_meta_box( 'issuediv' , 'post' , 'normal' );
}
//add our custom meta box
@ericpedia
ericpedia / gist:1151032
Created August 17, 2011 07:30
tag interface not saving
<?php
//remove default metabox
//change TAXONOMY_NAME to your taxonomy name
// My taxonomy slug is 'issue'
function remove_post_custom_fields() {
remove_meta_box( 'issuediv' , 'post' , 'normal' );
}
@ericpedia
ericpedia / gist:1151160
Created August 17, 2011 09:18
tag interface for category in wordpress
<?php
//remove default metabox
//change TAXONOMY_NAME to your taxonomy name
add_action( 'admin_menu' , 'remove_post_custom_fields' );
function remove_post_custom_fields() {
remove_meta_box( 'categorydiv' , 'post' , 'normal' );
}
@ericpedia
ericpedia / dteam.php
Created August 24, 2011 16:32
AJAX taxonomy filter/search plugin file 1 of 2
<?php
// see the live version at http://bit.ly/q0qfqF
// click "Filter your results" to expand search panel
/**
* @package DTeam
* @version 1.0
*/
/*
@ericpedia
ericpedia / ajax.php
Created August 24, 2011 16:35
AJAX taxonomy filter/search plugin file 2 of 2
<?php
require_once('../../../wp-load.php');
global $wpdb;
$ajax = isset($_POST['ajax']) ? $_POST['ajax'] : '';
switch($ajax) {
case 'search':
$people = isset($_POST['people']) ? $_POST['people'] : '';
$issue = isset($_POST['issue']) ? $_POST['issue'] : '';
$topic = isset($_POST['topic']) ? $_POST['topic'] : '';
$type = isset($_POST['type']) ? $_POST['type'] : '';