Skip to content

Instantly share code, notes, and snippets.

View jonathanstegall's full-sized avatar

Jonathan Stegall jonathanstegall

View GitHub Profile
SELECT u.ID, u.user_email, count(distinct ifnull(c.comment_ID, 0)) as count,
(
SELECT GROUP_CONCAT( m.meta_value )
FROM wp_usermeta m
WHERE m.meta_key = 'member_level' AND m.user_id = u.ID AND m.meta_value != 'Non-member'
) as member_level
FROM wp_users u
JOIN wp_comments c ON u.ID = c.user_id
WHERE comment_approved = 1 AND comment_type IN ("comment", "") AND c.user_id <> 0
GROUP BY u.ID
SELECT
ID,
CONCAT(
(
SELECT option_value
FROM wp_options
WHERE option_name = 'siteurl'
),
'/', (
SELECT slug FROM wp_terms WHERE term_id IN
@jonathanstegall
jonathanstegall / migrate.sql
Created April 3, 2019 21:11
migrate from VIP to local environment
// first, run cat ~/Desktop/sql/*.sql | mysql -u root -p minnpost.wordpress in terminal
DELETE FROM wp_options WHERE option_name = 'jetpack_options';
UPDATE wp_options SET option_value = 'https://minnpost-wordpress.test' WHERE option_name = 'siteurl';
UPDATE wp_options SET option_value = 'https://minnpost-wordpress.test' WHERE option_name = 'home';
@jonathanstegall
jonathanstegall / verify-imagick.php
Created March 18, 2019 20:44
verify that imagemagick and imagick are installed
<?php
error_reporting(E_ALL);
ini_set( 'display_errors','1');
/* Create a new imagick object */
$im = new Imagick();
/* Create new image. This will be used as fill pattern */
$im->newPseudoImage(50, 50, "gradient:red-black");
@jonathanstegall
jonathanstegall / story-count-by-category-and-month.sql
Last active October 5, 2022 02:47
get a count of stories for each category by year/month
SELECT t.term_id, REPLACE(t.name, '&amp;', '&') as name, COUNT(p.ID) as post_count, YEAR(post_date) as year, MONTH(post_date) as month
FROM wp_terms t
INNER JOIN wp_term_taxonomy tax ON t.term_id = tax.term_id
INNER JOIN wp_term_relationships r ON tax.term_taxonomy_id = r.term_taxonomy_id
INNER JOIN wp_posts p ON r.object_id = p.ID
WHERE tax.taxonomy = 'category' and YEAR(post_date) >= YEAR(CURDATE()) and p.post_type = 'post' and p.post_status = 'publish'
GROUP BY term_id, YEAR(post_date), MONTH(post_date)
ORDER BY YEAR(post_date) DESC, MONTH(post_date) DESC, t.name ASC;
@jonathanstegall
jonathanstegall / valet-error-log.sh
Created December 18, 2018 18:01
new path for valet Nginx error log
sublime ~/.config/valet/Log/nginx-error.log
@jonathanstegall
jonathanstegall / .htaccess-noindex
Created December 13, 2018 15:29
keep stage and dev subdomains out of search indexes
# keep stage and dev out of indexes
<IfModule mod_headers.c>
<IfModule mod_setenvif.c>
SetEnvIf Host ^stage\. NOINDEX
SetEnvIf Host ^dev\. NOINDEX
Header set X-Robots-Tag "noindex, nofollow, noarchive" env=NOINDEX
</IfModule>
</IfModule>
# Varnish's cache can be purged by restarting the service:
systemctl restart varnish
@jonathanstegall
jonathanstegall / breaking-excerpt.php
Last active July 20, 2018 18:41
excerpt code that breaks raw html pro plugin
<?php
/**
* Remove the default WordPress excerpt field.
*/
function theme_admin_hide_excerpt_field() {
add_action( 'dbx_post_advanced', '_theme_admin_hide_excerpt_field' );
}
add_filter( 'admin_init', 'theme_admin_hide_excerpt_field' );
function _theme_admin_hide_excerpt_field() {
$screen = get_current_screen();
# remove .git from a svn repository. this is useful for WP plugins
find . -name ".git" -exec svn delete '{}' \;