Skip to content

Instantly share code, notes, and snippets.

<?php /***
Man after thinking about this for some time I can't think of a good way to do this without doing a lot of huge queries. Hmmm…
Well you have to have a query to get all of the posts so you can determine how many pages of results you're dealing with. You might be better off writing a custom SQL query for this and just selecting the ID column. It will be quicker than selecting a whole bunch of other columns you don't really need.
Once you have all of the post IDs, you can figure out which terms are relevant for each taxonomy using wp_get_object_terms (pass it an array of IDs and a string for the taxonomy).
Loop over this array of term objects and make a new array that just contains term IDs. Now you can loop over all of the terms in the taxonomy and do a conditional to determine if the term ID is in the array of matched IDs we made earlier. If it is, display it as bold in your drop down, otherwise gray it out.
You're going to have to do a lot of experimenting to get it working just right but tha
@ericpedia
ericpedia / gist:1340236
Created November 4, 2011 19:20
docraptor excluding scripts
myHTML = jQuery('html').clone();
// I tried removing elements one by one, like this:
myHTML.find('script[src*="aloha"], link[href*="aloha"], .admin-only, script[src*="pro-player"], script[src*="proplayer"], script[src*="colorbox"], script[src*="sharethis"], script:contains("Aloha"), script:contains("colorbox"), script:contains("analytics"), script[src*="analytics"], script:contains("stLight"), style:contains("AdBlock"), style[style*="display: none !important"], script:contains("front-end-editor"), script:contains("thickbox"), link:contains("admin-bar"), #wpadminbar').remove();
// another way to do it is to remove all scripts except a particular script, like this:
myHTML.find('script:not([src*="typekit"])').remove();
// at one point I just removed all scripts, to see if that helped (not really)
@ericpedia
ericpedia / gist:1346372
Created November 7, 2011 22:11
fig shortcode
<?php
function epi_FiguresTablesCharts_shortcode ( $atts, $content=null ) {
extract( shortcode_atts( array(
'label' => null,
'url' => null,
'style' => null,
'width' => null,
'hidelabel' => null,
'inline' => null,
@ericpedia
ericpedia / shortcode.fig.on.php
Created November 15, 2011 04:59
fig shortcode 2011-11-14
<?php
/****************************************************
Figures and Tables - [fig] and [figwrapper][/figwrapper]
****************************************************/
function my_FiguresTablesCharts_shortcode ( $atts, $content=null ) {
extract( shortcode_atts( array(
'label' => null,
'url' => null,
@ericpedia
ericpedia / gist:1831001
Created February 14, 2012 22:16
Split TinyMCE table above selected row into tbody and thead
splitTbodyThead: function() {
var ed = tinyMCE.activeEditor;
var selection = ed.selection.getContent();
var element = ed.dom.getParent(ed.selection.getNode(), 'tr');
// Give the selected row a class so we can find it later
ed.dom.setAttrib( element, 'data-tinymce', 'split');
@ericpedia
ericpedia / gist:1857682
Created February 18, 2012 05:48
:nth-col test table with <th> rowspans
<table><colgroup> <col width="15%" /> <col width="25%" /> <col span="4" width="30%" /> <col class="table-division-left" span="4" width="30%" /></colgroup>
<thead>
<tr>
<th scope="colgroup"></th>
<th scope="colgroup"></th>
<th scope="colgroup" colspan="4">Share with ESI</th>
<th scope="colgroup" colspan="4">Percentage-point change</th>
</tr>
<tr>
<th scope="col"></th>
@ericpedia
ericpedia / gist:3583170
Created September 1, 2012 18:52
PHP crop blank space around image
<?php
/** Loop through all the files in a folder **/
function loop_through_folder_by_extension($path, $extension) {
$processedFiles = array();
$errors = array();
foreach ( "{$path}/*.{$extension}" as $filename ) {
@ericpedia
ericpedia / gist:3593283
Created September 2, 2012 01:23
WP - Add custom field and term based on title when saving a post
// Problem: This adds the term to the taxonomy, but it does not connect it to the post. It seems to connect it to the revision or something.
// Problem: When the title updates, the custom field does not update until after saving twice.
add_filter ('title_save_pre','w559_title_hook');
function w559_title_hook($title) {
global $post;
$id = get_the_id();
@ericpedia
ericpedia / gist:3626113
Created September 4, 2012 20:30
two queries on one page won't work?
<?php
/**
* The template for displaying Search Results pages.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/
?>
@ericpedia
ericpedia / gist:3903803
Created October 17, 2012 05:09
Relevanssi returns zero results in custom query
<?php
$wp_query = new WP_Query( array(
'post_type' => 'any',
'posts_per_page' => '5',
// If we just set the vars above, the query returns posts as expected. But setting
// a search term causes the query to return 0 results (if Relevanssi is activated)
's' => 'test', // or get_search_query(), or a variable containing search term