Skip to content

Instantly share code, notes, and snippets.

View nielsvr's full-sized avatar

Niels van Renselaar nielsvr

View GitHub Profile
@nielsvr
nielsvr / wpml-config.xml
Created October 26, 2015 09:51
Make strings in WP Customizer translatable with WPML
<wpml-config>
<admin-texts>
<key name="theme_mods_yourtheme">
<key name="option_name_1" />
<key name="option_name_2" />
</key>
</admin-texts>
</wpml-config>
@nielsvr
nielsvr / gist:a0ae56c0b267b29a0cbd
Last active August 29, 2015 14:24
Custom rewrite for WordPress with custom template
<?php
// enables you to use example url "/showcase/case-title" and pushes it to "single-showcases.php" template for rendering
function mu_custom_rewrites() {
global $wp;
$wp->add_query_var('case');
add_rewrite_tag('%case%', '([^/]+)', 'case=');
@nielsvr
nielsvr / posts.php
Created October 14, 2014 18:35
Get posts starting with a letter
<?php
add_filter( 'posts_where', 'start_with_letter', 10, 2 );
function start_with_letter( $where, &$wp_query )
{
global $wpdb;
if ( $start_with_letter = $wp_query->get( 'start_with_letter' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( like_escape( $start_with_letter ) ) . '%\'';
}
@nielsvr
nielsvr / query.php
Created October 3, 2014 10:54
Running dbDelta on a different database then WordPress
<?php
/*
* Using a different database with dbDelta
*/
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
@nielsvr
nielsvr / admin.js
Created September 26, 2014 08:27
Setting the default customer note in WooCommerce to private
jQuery(document).ready(function() {
if( jQuery("#order_note_type") ) {
jQuery('#order_note_type :nth-child(2)').prop('selected', true);
}
});
<?php
function display_posts_function() {
$return = "";
$cats = get_categories('hide_empty=0&orderby=name&order=asc');
foreach ($cats as $cat) :
@nielsvr
nielsvr / single.php
Created July 16, 2014 08:34
Want to get the previous post and next post data in WordPress? Use this in the loop
<?php
/*
* Want to get the previous post and next post data in WordPress? Use this in the loop
* get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy )
*/
$prev_post = get_adjacent_post( false, false, true ); // retrieves previous post in current post type, with no exclusions
$next_post = get_adjacent_post( false, false, false ); // retrieves next post in current post type, with no exclusions
@nielsvr
nielsvr / single.php
Created July 16, 2014 08:34
Want to get the previous post and next post data in WordPress?
<?php
/*
* Want to get the previous post and next post data in WordPress? Use this in the loop
* get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy )
*/
$prev_post = get_adjacent_post( false, false, true ); // retrieves previous post in current post type, with no exclusions
$next_post = get_adjacent_post( false, false, false ); // retrieves next post in current post type, with no exclusions
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]
@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