Skip to content

Instantly share code, notes, and snippets.

View bookchiq's full-sized avatar

Sarah Lewis bookchiq

View GitHub Profile
@bookchiq
bookchiq / Follow redirects with cURL.sh
Created March 16, 2021 15:51
Follow redirects with cURL (useful for troubleshooting headers and 301/302 issues)
curl -iLvs https://www.example.org/member-portal/ 1> /dev/null
@bookchiq
bookchiq / delete_orphaned_postmeta.sql
Created July 10, 2020 17:02
SQL to delete orphaned postmeta in WordPress
DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL
@bookchiq
bookchiq / find-missing-postmeta.sql
Created May 18, 2020 17:47
Find WordPress posts that are missing a specific custom field/postmeta
SELECT *
FROM wp_posts
WHERE
post_type = "ycd_individual" AND
post_status = "publish" AND
ID NOT IN (
SELECT wp.ID
FROM wp_posts wp
LEFT JOIN wp_postmeta pm ON wp.ID = pm.post_id
WHERE
@bookchiq
bookchiq / delete_duplicate_posts_by_meta_value.sql
Created April 14, 2020 14:53
Delete duplicate WordPress posts (where duplication is determined by a post meta value) and subsequently orphaned post meta
DELETE FROM wp_posts WHERE ID IN (
SELECT post_id
FROM wp_postmeta
INNER JOIN (
SELECT meta_value
FROM wp_postmeta
WHERE meta_key = 'meta_key_name'
GROUP BY meta_value
HAVING COUNT( meta_value ) > 1) dup
ON wp_postmeta.meta_value = dup.meta_value
@bookchiq
bookchiq / 301-redirect-process-snippets.md
Last active October 22, 2019 19:11
301 redirect process snippets

Get the ID numbers from a list of pattern URLs in a format like ^/about/content.cfm?itemnumber=2885&navitemnumber=537?$

  • Search: ^.*?=(\d+).*$
  • Replace: $1

Get the slugs from a list of destination URLs

  • Search: ^.*?([^\/]*?)\/$
  • Replace: $1

Set it up as metadata in WordPress via a search-by-slug process

@bookchiq
bookchiq / reposition-quick-page-post-redirect-meta-box.php
Created April 11, 2019 17:32
Re-position "Quick Page/Post Redirect" plugin meta box to low priority. Just change "low" to "high" to put it at the top.
<?php
/**
* Filter Quick Page/Post Redirect Metabox Priority
* @author Sarah Lewis
* @link
*/
function sl_filter_quick_page_post_redirect_metabox_priority() {
return 'low'; // The options are 'high', 'core', 'default' or 'low' (plugin default is 'high').
}
@bookchiq
bookchiq / delete-orphaned-featured-images.sql
Created February 7, 2019 21:12
WordPress: delete Featured Image relationships if the image no longer exists in the Media Library
@bookchiq
bookchiq / wp-autopopulate-taxonomy.php
Last active October 16, 2018 21:12 — forked from brenna/wp-autopopulate-taxonomy
WordPress function to auto-populate a taxonomy with a custom post type's entries.
<?php
/**
* Register our custom taxonomy.
*
* @return void
*/
function gist_5f2e8bcd3217698fb4947e120f178686_custom_tax_init() {
// Set some options for our new custom taxonomy.
$args = array(
'label' => __( 'My Custom Taxonomy' ),
@bookchiq
bookchiq / Reveal date-matched duplicates.js
Created October 11, 2018 20:07
The WordPress plugin "Fix Duplicates" [ https://wordpress.org/plugins/fix-duplicates/ ] tests for duplication by title. In my situation, we'd inadvertently double-imported some posts, but had a lot of different posts with the same titles, so I needed a way to see which ones were truly duplicates (based on having the same timestamp) vs. just the …
jQuery( 'table.wp-list-table.widefat.fixed.posts tr' ).css( 'display', 'table-row' );
jQuery( 'tbody[id^="fix-duplicates-group-"]' ).each( function() {
var rowWrapper = jQuery( this );
var matchingDateCount = 0;
var dates = new Array();
var matchedDates = new Array();
var dateCount = rowWrapper.find( 'tr td.date abbr' ).length;
rowWrapper.find( 'tr td.date abbr' ).each( function() {
var currentDate = jQuery( this ).text();
@bookchiq
bookchiq / p2a-marketo-rich-media-tweaks.js
Last active April 18, 2018 20:39
P2A Marketo Rich Media adjustments
jQuery( document ).ready( function( $ ) {
var moveMarketoRichMediaAround = function() {
var wrapperClass = '.RTP_RCMD2';
var pageWidth = $( 'body' ).width();
var targetSmallScreens = '.default-page-content > .fl-node-content';
var targetLargeScreens = '.marketo-rich-media > .custom-html-widget';
if ( 769 <= pageWidth ) {
// It's two-column, so put it in the sidebar widget if it's not already there