Skip to content

Instantly share code, notes, and snippets.

View not-only-code's full-sized avatar
👾
Looking for work!

Carlos Sanz García not-only-code

👾
Looking for work!
View GitHub Profile
@not-only-code
not-only-code / gist:2889579
Created June 7, 2012 15:47
adds meta query on Wordpress search
/**
* adds meta values on search query
*
* @param object $query
*
**/
function custom_search_query( $query ) {
if ( !is_admin() && $query->is_search ) {
$query->set('meta_query', array(
array(
@not-only-code
not-only-code / functions.php
Last active October 5, 2015 22:47
Wordpress: get hierarchical post ancestor
/**
* get hierarchical post ancestor (level 0)
*
* @param int|object $post
* @return object post ancestor
*
* @usage get_post_ancestor(131) | get_post_ancestor($post)
*
**/
function get_post_ancestor( $post = false ) {
@not-only-code
not-only-code / .htaccess
Last active October 5, 2015 22:58
Web fonts .htaccess snippet
# BEGIN REQUIRED FOR WEBFONTS
AddType font/ttf .ttf
AddType font/eot .eot
AddType font/otf .otf
AddType font/woff .woff
<FilesMatch "\.(ttf|otf|eot|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
@not-only-code
not-only-code / endpoints.php
Created August 31, 2012 10:57 — forked from joncave/endpoints.php
WP_Rewrite endpoints demo
<?php
/*
Plugin Name: WP_Rewrite endpoints demo
Description: A plugin giving example usage of the WP_Rewrite endpoint API
Plugin URI: http://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/
Author: Jon Cave
Author URI: http://joncave.co.uk/
*/
function makeplugins_endpoints_add_endpoint() {
@not-only-code
not-only-code / dabblet.css
Created December 6, 2012 19:34
stitched-effect
div {
margin: 50px auto;
}
/**
* stitched-effect
*/
.stitched-effect {
position: relative;
width: 300px;
@not-only-code
not-only-code / functions.php
Created December 7, 2012 12:59
Theming Jigoshop: create your custom product types
/**
* Helper functions to add / remove array of terms
*
* @package MyTheme
* @since 1.0
*
**/
function _add_terms( $terms, $taxonomy = 'category' ) {
if ( !is_array($terms) || empty($terms)) return;
@not-only-code
not-only-code / gist:4562606
Last active December 11, 2015 06:58
Effectively Containing Floats, a better clearfix technique
/* Effectively Containing Floats · @shayhowe · http://www.shayhowe.com */
.group:before,
.group:after {
content: "";
display: table;
}
.group:after {
clear: both;
}
@not-only-code
not-only-code / functions.php
Last active December 14, 2015 01:09
return only the top level terms of the object/s
/**
* get top level object terms
* @package default
* @version 1.0
**/
function _get_object_parent_terms ($object, $taxonomies, $args = array()) {
$object_terms = wp_get_object_terms($object, $taxonomies, $args);
$output = array();
<?php
function _register_post_type( $post_type = '', $args = array() ) {
if ( empty( $post_type ) )
return;
$singular = empty( $args['singular'] ) ? $post_type : $args['singular'];
$singular = str_replace( '_', ' ', $singular );
$singular = ucwords( $singular );
$plural = empty( $args['plural'] ) ? "{$singular}s" : $args['plural'];
$plural = ucwords( $plural );
@not-only-code
not-only-code / main.coffee
Last active December 18, 2015 21:49
Backbone custom REST API urls
###
This test use Apiari.io REST sketch
###
class MyModel extends Backbone.Model
rootUrl: 'http://backbonecustomrest.apiary.io'
customUrls:
'read': '/my-path/1/get'
'create': '/my-path/1/create'
'update': '/my-path/1/update'
'delete': '/my-path/1/delete'