Skip to content

Instantly share code, notes, and snippets.

View kaynenh's full-sized avatar

Kaynen Heikkinen kaynenh

View GitHub Profile
.issuuembed > div > div {
background: white !Important;
}
@kaynenh
kaynenh / gist:1fd46daad67d6287bde825ccb01da616
Created October 17, 2016 16:16
Wordpress Get All Categories in a Single Column by Post ID from MySQL
SELECT p1.id, p1.post_title, p1.post_name,
(SELECT GROUP_CONCAT(wt.name SEPARATOR ', ') FROM wp_posts p2
INNER JOIN wp_term_relationships r ON r.object_id=p2.ID
INNER JOIN wp_term_taxonomy t ON t.term_taxonomy_id = r.term_taxonomy_id
INNER JOIN wp_terms wt on wt.term_id = t.term_id
WHERE t.taxonomy="category"
AND p2.id = p1.id
) as categories
FROM wp_posts p1
WHERE p1.post_status = 'publish'
@kaynenh
kaynenh / gist:024f350c2eead8bd6fa15837c306456d
Created September 26, 2016 13:55
Wordpress Custom Meta Description based on Faceted Categories
function add_meta_tags() {
global $post;
if ( is_archive() || is_home()) {
/*
* CONTEXT CLASS
* Here we go, need to create a context for the library pages and its facets
*/
class Context
{
public $isContentType = false;
@kaynenh
kaynenh / Apache Access Logs to CSV with regex
Created August 17, 2016 16:13
Use Regex to create CSV of raw access logs.
<?php
/*
^(.+).log(?:\.(?:\d+))?(?:\.gz)?\:((?:\d|\.)+)\s-\s-\s\[((?:\d{2})\/(?:\w{3,4})\/(?:\d{4})):(\S+)\s\+(?:\d+)\]\s\"GET \/wp-content\/uploads\/(?:mp3s\/)?(\S+)\s\S+\s(\d{3})\s\d+\s\S+\s\"(.*)\"$
*/
$re = "/^(.+).log(?:\\.(?:\\d+))?(?:\\.gz)?\\:((?:\\d|\\.)+)\\s-\\s-\\s\\[((?:\\d{2})\\/(?:\\w{3,4})\\/(?:\\d{4})):(\\S+)\\s\\+(?:\\d+)\\]\\s\\\"GET \\/wp-content\\/uploads\\/(?:mp3s\\/)?(\\S+)\\s\\S+\\s(\\d{3})\\s\\d+\\s\\S+\\s\\\"(.*)\\\"$/mi";
$file = file_get_contents('search_results.txt');
preg_match_all($re, $file, $matches, PREG_SET_ORDER);
foreach($matches as $match) {
$comma_separated = implode("`,`", $match);
echo '`'.$comma_separated . "`<br />";
@kaynenh
kaynenh / remove-node-from-loaded-dom.php
Created May 11, 2016 15:25
Shell concept for removing node from loaded html
$string = "<<<HTML" . $this->remoteResponse->getBody() . "
HTML";
$dom = new DOMDocument();
$dom->loadHTML($string);
$xpath = new DOMXpath($dom);
$nlist = $xpath->query("//button[@id='id-of-button']");
$node = $nlist->item(0);
$node->parentNode->removeChild($node);
var_dump($this);
// Pullquote with parameters
function pullquote( $title, $content = null ) {
extract(shortcode_atts(array(
'title' => 'title'
), $title));
return "<div class'wrapper'><button>{$title}</button><h3>{$content}</h3></div>";
}
add_shortcode('pullquote', 'pullquote');
//Use in content with this