Skip to content

Instantly share code, notes, and snippets.

<?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: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);
@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: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: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>';
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)) {