Skip to content

Instantly share code, notes, and snippets.

@waqasy
waqasy / wp-better-side-nav.php
Created October 7, 2018 19:41 — forked from MikeNGarrett/wp-better-side-nav.php
Instead of wp_list_pages where all children and grandchildren of the current page are listed out this method lists the parent page, siblings of the current page (in menu order) and when it gets to the current page it lists out the children.
<?php /* Not as simple as it sounds */ ?>
<div class="side-nav">
<div class="holder">
<ul>
<?php
if (isset($post->post_parent) && $post->post_parent > 0) {
$permalink = get_permalink($post->post_parent);
$parent_title = get_the_title($post->post_parent);
print('<li class="page_item page-parent"><a href="'.$permalink.'">'.$parent_title.'</a></li>');
$parent = $post->post_parent;
@waqasy
waqasy / php-UA.php
Created July 13, 2018 05:45 — forked from walkergv/php-UA.php
Simple Event Tracking with Measurement Protocol Using cURL and PHP (plus redirect)
<?
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://www.google-analytics.com/collect?v=1&tid=[UA-XXXXXXXXX-1]&cid=[RANDOM_INTEGER_OR_GUID]&t=event&ec=[EVENT_CATEGORY]&ea=[EVENT_ACTION]&el=[EVENT_LABEL]',
CURLOPT_USERAGENT => 'Vanity-URL-Tracker',
));
$resp = curl_exec($curl);
curl_close($curl);
header("HTTP/1.1 301 Moved Permanently");
@waqasy
waqasy / serviceworker.js
Created July 9, 2018 18:08 — forked from ngokevin/serviceworker.js
Service Worker Template - cache-else-network + network-else-cache
var VERSION = 'v1';
var cacheFirstFiles = [
// ADDME: Add paths and URLs to pull from cache first if it has been loaded before. Else fetch from network.
// If loading from cache, fetch from network in the background to update the resource. Examples:
// 'assets/img/logo.png',
// 'assets/models/controller.gltf',
];
@waqasy
waqasy / time
Created July 5, 2018 14:26
get PST date time in php
<?php
$timezone = -8; //(GMT -5:00) EST (U.S. & Canada)
$date = new DateTime("now", new DateTimeZone('America/Los_Angeles') );
echo $date->format('j F Y, h:i:s A').'<br>';
echo gmdate("Y/m/j H:i:s", time() + 3600*($timezone+date("I")));
?>
@waqasy
waqasy / bsearch-meta-field.php
Created June 15, 2018 09:18 — forked from ajaydsouza/bsearch-meta-field.php
Better Search API Examples
<?php
// Fixes to disregard Hidden products and to add Author Billing field to Better Search plugin queries
function filter_bsearch_posts_join( $join ) {
global $wpdb, $author_search;
$join .= "
INNER JOIN $wpdb->postmeta AS pm ON ($wpdb->posts.ID = pm.post_id)
";
if ( $author_search ) {
$join .= "
INNER JOIN $wpdb->postmeta AS pma ON ($wpdb->posts.ID = pma.post_id)
@waqasy
waqasy / featured-posts-pattern-helper-functions.php
Created June 1, 2018 00:30 — forked from luistinygod/featured-posts-pattern-helper-functions.php
WordPress: Manage featured posts using WordPress menus
@waqasy
waqasy / Convert Custom Taxonomy to Custom Post Type
Created May 28, 2018 20:59 — forked from Strap1/Convert Custom Taxonomy to Custom Post Type
A very hacky and quick way to transfer a Custom Taxonomy to Custom Post Type and transfer associated metadata to Custom Meta Fields. Note: You can use this if it fits your needs, but it is custom to my set up. Use in a testing environment. It's a plugin with no interface, runs on activation and depending on the amount of data, may hit PHP timeou…
<?php
/*
Plugin Name: Convert Custom Taxonomy to Custom Post Type
Plugin URI: N/A
Description: A plugin to convert a Custom Taxonomy to a Custom Post Type and transfer associated metadata.
Version: 0.1
Author: Strap1
Author URI: http:/www.hiphopinenglish.com
/** Convert Taxonomy '%name%' to CPT '%name%' **/
@waqasy
waqasy / custom-post-taxonomy-permalinks.php
Created May 28, 2018 20:17 — forked from kasparsd/custom-post-taxonomy-permalinks.php
Create permalink structure URLs for custom post types that include all parent terms from a custom taxonomy
<?php
/*
Term Archive Pages:
- http://example.com/recipes/dinner/
- http://example.com/recipes/breakfast,brunch/
Single Recipe Pages:
- http://example.com/recipes/dinner/soup-title/
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@waqasy
waqasy / tanggal_regex_php
Created May 24, 2018 10:47 — forked from pujie/tanggal_regex_php
php regex for date (id)
<?php
echo '<h2>yyyy/mm/dd</h2>';
preg_match('/(19[5-9][0-9]|20[0-9][0-9])[\/-](0[1-9]|1[0-2])[\/-](0[1-9]|1[0-9]|2[0-9]|3[01])/','2011/12/30',$match);
foreach($match as $key=>$val){
echo $key . ' => ' . $val . '<br>';
}
echo '<h2>dd/mm/yyyy</h2>';
preg_match('/(0[1-9]|1[0-9]|2[0-9]|3[01])[\/-](0[1-9]|1[0-2])[\/-](19[5-9][0-9]|20[0-9][0-9])/','30/12/2011',$match);
foreach($match as $key=>$val){