Skip to content

Instantly share code, notes, and snippets.

View aliciaduffy's full-sized avatar

Alicia Duffy aliciaduffy

View GitHub Profile
@aliciaduffy
aliciaduffy / gist:63d0910be215f162ec04
Created August 8, 2014 12:52
get_adjacent_posts()
<?php
/**
* Retrieve adjacent post.
*
* Can either be next or previous post.
*
* @since 2.5.0
*
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term.
* @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
@aliciaduffy
aliciaduffy / gist:28e9f84b4dcba6243563
Last active August 29, 2015 14:00
Most Common Value/Answer - Gravity Forms Merge Tag
<?php
/* Add {most_common} merge tag.
* For assigning a unique quiz result based on most common quiz answer (A, B, C, D, value) */
add_filter('gform_custom_merge_tags', 'custom_merge_tags', 10, 4);
function custom_merge_tags($merge_tags, $form_id, $fields, $element_id) {
$merge_tags[] = array('label' => 'Most Common Answer', 'tag' => '{most_common}');
return $merge_tags;
}
/* Replace merge tag with most common value */
@aliciaduffy
aliciaduffy / gist:11371805
Last active August 29, 2015 14:00
Quiz Field Change
<?php
add_filter( "gform_field_choices", "custom_gravity_add_media_credit", 10, 2 );
function custom_gravity_add_media_credit( $choices, $field ) {
// If field isn't quiz or radio, and isn't admin
if ( ( $field["type"] != "radio" && $field["type"] != "quiz" ) || is_admin() ) {
return $choices;
}
// If isn't an image layout
if ( $field["answerLayoutField"] == "list" || !$field["answerLayoutField"] ) {
@aliciaduffy
aliciaduffy / gist:11290503
Created April 25, 2014 13:58
No-Repeat Background - HTML Email / Outlook 2007 compatible
<div style="background-color: #cee9f4;">
<!--[if gte mso 9]>
<v:background xmlns:v="urn:schemas-microsoft-com:vml" fill="t">
<v:fill type="tile" src="http://static4.businessinsider.com/image/51b5d13369bedde54a000008/peta-goes-the-uncontroversial-route-and-hires-lil-bub-as-a-spokescat.jpg" color="#cee9f4" />
</v:background>
<![endif]-->
<table id="backgroundTable" style="background-image: url(http://static4.businessinsider.com/image/51b5d13369bedde54a000008/peta-goes-the-uncontroversial-route-and-hires-lil-bub-as-a-spokescat.jpg); background-repeat: no-repeat;" border="0" cellspacing="0" cellpadding="0" width="100%" height="100%" align="center" background="http://static4.businessinsider.com/image/51b5d13369bedde54a000008/peta-goes-the-uncontroversial-route-and-hires-lil-bub-as-a-spokescat.jpg">
<!-- REST OF EMAIL -->
@aliciaduffy
aliciaduffy / load-related-attachments.php
Last active August 29, 2015 14:00
WordPress: Show all posts containing media/attachment
@aliciaduffy
aliciaduffy / gist:8791099
Last active August 29, 2015 13:56
Default Sort WordPress Post Types Admin by Date
<?php
function duffy_custom_post_types_admin_order($wp_query) {
if ( is_admin && ( get_query_var('orderby') == 'menu_order title' ) ) {
// 'orderby' value can be any column name
$wp_query->set('orderby', 'date');
// 'order' value can be ASC or DESC
$wp_query->set('order', 'DESC');
}
}
@aliciaduffy
aliciaduffy / gist:7912286
Last active December 31, 2015 01:09
WordPress query two categories at once - ex. http://website.com/?category_name=cats+dogs
<?php
function duffy_category_search_logic( $query ) {
if ( !isset( $query->query_vars[ 'category_name' ] ) )
return $query;
// split cat query on a space to get IDs separated by '+' in URL
$cats = explode( ' ', $query->query_vars[ 'category_name' ] );
if ( count( $cats ) > 1 ) {
@aliciaduffy
aliciaduffy / gist:7912196
Last active December 31, 2015 01:09
WordPress override template hierarchy/suggestions
<?php
/**
* Template hierarchy overrides
* Use taxonomy or archive templates for specific cat and search queries
*/
function duffy_override_category_template( $template ) {
if ( is_category() && ( 'custom-tax' == get_query_var( 'taxonomy' ) ) ) {
return get_stylesheet_directory() . '/taxonomy-custom-tax.php';
}
if ( is_search() && ( 'custom-type' == get_query_var( 'post_type' ) ) ) {
@aliciaduffy
aliciaduffy / comments.php
Last active April 4, 2023 14:55
Sort Comments by GD Star Rating Thumbs Up. Store thumbs up count in the comment_karma column
<?php /* Sort comments by number of thumbs up */
$post_id = get_the_ID();
$comments = get_comments(array(
'post_id' => $post_id,
"orderby" => "comment_karma",
"order" => "DESC"
));
?>
<?php wp_list_comments('', $comments); ?>
@aliciaduffy
aliciaduffy / Drupal Views Hook
Created July 9, 2013 23:08
For hiding/showing fields based on exposed filter setting.
function MYMODULE_views_views_post_build(&$view) {
if ($view->name == 'views_name') {
if (isset($view->exposed_input['field_geofield_distance'])) {
if (isset($view->field['field_geofield_distance'])) {
$view->field['field_geofield_distance']->options['exclude'] = TRUE;
}
} else {
if (isset($view->field['field_geofield_distance_1'])) {
$view->field['field_geofield_distance_1']->options['exclude'] = TRUE;
}