Skip to content

Instantly share code, notes, and snippets.

View freekrai's full-sized avatar

Roger Stringer freekrai

View GitHub Profile
@freekrai
freekrai / gist:8526883
Last active January 3, 2016 22:09
search_by_post_and_meta_fields
<?php
function search_by_post_and_meta_fields($args) {
global $wpdb;
$defaults = array(
'post_type' => 'post',
'post_fields_to_search' => false,
'meta_fields_to search' => false,
'search_term' => false
);
extract(wp_parse_args($args, $defaults));
@freekrai
freekrai / gist:8526899
Last active January 3, 2016 22:09
search
<?php
$args = array(
'post_type' => 'listing',
'post_fields_to_search' => array('post_title', 'post_content'),
'meta_fields_to_search' => array('_tags'),
'search_term' => 'hello'
);
$post_ids = search_by_post_and_meta_fields($args);
foreach($post_ids as $post_id) {
$post = get_post($post_id);
<?php
class post_search_meta {
function post_search_meta() {
add_filter( 'posts_where' , array( $this , 'where' ) );
add_filter( 'posts_join' , array( $this , 'join' ) );
add_filter( 'posts_groupby' , array( $this , 'group' ) );
}
function group( $groupby ) {
global $wp_query, $wpdb;
if( empty($groupby) ) $groupby = "{$wpdb->posts}.ID";
@freekrai
freekrai / hash_djb2.php
Created January 20, 2014 19:24
DJB2 Hash in PHP
<?php
function hash_djb2($str){
$hash = 5381;
$length = strlen($str);
for($i = 0; $i &lt; $length; $i++) {
$hash = ( ($hash << 5) + $hash ) + $str[$i];
}
return ($hash & 0xFFFFFFFF);
}
@freekrai
freekrai / related.php
Created January 20, 2014 19:27
Related Posts by tag
@freekrai
freekrai / related.class.php
Last active January 4, 2016 03:49
Related Posts without a plugin.
@freekrai
freekrai / single.php
Created January 22, 2014 19:14
Using related posts...
<?php
// Place the following code inside your single.php:
include("related.class.php");
$related = new rs_related();
$postids = $related->get_related($post->ID,5);
if( count($postids) ){
?>
<h3>Related posts:</h3>
<ul>
<?php
$limit = 5;
$strictlimit = TRUE;
$weight = array(
'body'=>1,
'title'=>1,
'tax'=>1
);
@freekrai
freekrai / Config.class.php
Last active August 29, 2015 14:06
Mini-Laravel-Like config setup
<?php
/*
This is a simple, Laravel-like config sysytem, add files to a config/ folder in the following setup:
config.php:
<?php
return array(
'site_name' => 'My Website',
'site_strapline' => 'This is my first website'
);
@freekrai
freekrai / bootstrapfoo.css
Last active August 29, 2015 14:08
Boostrap Wufoo themes
/*! normalize.css v3.0.1 | MIT License | git.io/normalize */
html {
font-family: sans-serif;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
body {
margin: 0;
}
article,