Skip to content

Instantly share code, notes, and snippets.

Avatar

Darrin dboutote

View GitHub Profile
@dboutote
dboutote / hide-wp-status-links.php
Created Apr 19, 2016
[WordPress] Hide status link in the Posts table
View hide-wp-status-links.php
@dboutote
dboutote / random-post-tags.php
Created Apr 15, 2016
[WordPress] Display random post tags.
View random-post-tags.php
<?php
$args = array(
'taxonomy' => 'post_tag',
'hide_empty' => 0
);
$tags = get_terms( $args );
$class_name = 'my-custom-class-name';
if ( ! empty( $tags ) && ! is_wp_error( $tags ) ) {
shuffle( $tags );
@dboutote
dboutote / bootstrap-link-pages.php
Created Mar 24, 2016
Bootstrap replacement for WordPress wp_link_pages() function.
View bootstrap-link-pages.php
View resize-div-on-keyup.js
(function ($) {
'use strict';
function change_avatar_div( e ){
var field = $(e.currentTarget);
var acw_avatar_div = field.closest('.acw-thumb-size-wrap').find('.acw-avatar');
if( acw_avatar_div.length ) {
var icon = $( '.acw-icon', acw_avatar_div);
@dboutote
dboutote / recent-grouped-comments.sql
Created Mar 13, 2016
[WordPress] Get recent comments grouped by post
View recent-grouped-comments.sql
SELECT c.*
FROM `dbdb`.`wp_comments` c
LEFT JOIN `dbdb`.`wp_comments` c2 ON c.comment_post_ID = c2.comment_post_ID AND c.comment_date_gmt < c2.comment_date_gmt
JOIN `dbdb`.`wp_posts` ON `dbdb`.`wp_posts`.ID = c.comment_post_ID
WHERE c2.comment_date_gmt is NULL
AND ( c.comment_approved = '1' )
AND c.comment_type NOT IN ('pingback', 'trackback')
AND `dbdb`.`wp_posts`.post_status IN ('publish')
AND `dbdb`.`wp_posts`.post_type IN ('post')
ORDER BY c.comment_date_gmt DESC
@dboutote
dboutote / group-recent-comment.sql
Last active Mar 13, 2016
[WordPress] Group Recent Comments by post ID, sort by comment date
View group-recent-comment.sql
SELECT c.comment_ID
FROM wp_comments c
JOIN
( SELECT wp_comments.comment_post_ID, max(wp_comments.comment_date_gmt) maxDate
FROM wp_comments
GROUP BY wp_comments.comment_post_ID
) c2
ON c.comment_date_gmt = c2.maxDate AND c.comment_post_ID = c2.comment_post_ID
JOIN wp_posts
ON wp_posts.ID = c.comment_post_ID
@dboutote
dboutote / feed_filter.php
Last active Feb 23, 2016
Limit a WordPress feed to one post type.
View feed_filter.php
<?php
function my_feed_filter($query) {
if ( $query->is_feed && 'cpt_shop' === $query->get('post_type') ) {
$query->set('order', 'asc');
$query->set('meta_key', '_alt_title');
$query->set('orderby', 'meta_value');
};
return $query;
};
add_filter('pre_get_posts','my_feed_filter');
@dboutote
dboutote / edit-tags.js
Last active Feb 20, 2016
Removes link around locked tags; removes <span> from title attr. term_name filter.
View edit-tags.js
( function ($) {
'use strict';
var locked_tags = $('table.tags .dashicons-lock').parents('a.row-title');
locked_tags.contents().unwrap().parent().wrapInner('<span class="row-title"></span>');
locked_tags.attr('title', function(){
return 'Edit "' + $.trim( $(this).html().replace(/<[^>]+>/ig,"") ) + '"';
});
View filter-terms-clauses.php
<?php
/**
* Filter the terms query SQL clauses.
*
* @see 'terms_clauses' filter in get_terms() wp-includes/taxonomy.php
*
* @since 0.1.0
*
* @todo add filter for $allowed_orderby_keys
@dboutote
dboutote / category_tax_fix.php
Created Jan 11, 2016
Instruct WordPress to search on all post types when doing a category taxonomy query.
View category_tax_fix.php
<?php
function post_type_category_fix($request) {
if ( isset($request['category_name']) && !isset($request['post_type']) )
$request['post_type'] = 'any';
return $request;
};
add_filter('request', 'post_type_category_fix');
You can’t perform that action at this time.