Skip to content

Instantly share code, notes, and snippets.

[
{
"id" : "0",
"url" : "https://sample.com/url/",
"picture" : "assets/img/placeholder.jpg",
"role" : "Role Here",
"name" : "John Doe",
"expertise" : "Expertise here",
"searchfield" : "John Doe Role Here Expertise here"
},
@alimoshen
alimoshen / easyAutocomplete.js
Created January 30, 2018 16:59
easyAutocomplete
/*
* easy-autocomplete
* jQuery plugin for autocompletion
*
* @author Łukasz Pawełczak (http://github.com/pawelczak)
* @version 1.3.5
* Copyright License:
*/
/*
@alimoshen
alimoshen / profile-autocomplete.scss
Created January 30, 2018 16:58
Easy Autocomplete Profile Styling
.easy-autocomplete { width: 100% !important; position: relative;
a { display: block; }
.easy-autocomplete input { float: none;
&:hover, &:focus { box-shadow: none; border: none; }
}
.easy-autocomplete-container { left: 0; right: 0; margin: 0 auto; position: absolute; width: 70%; z-index: 15;
ul { display: none; margin-top: 0; padding-bottom: 0; padding-left: 0; position: relative; top: -1px; background: $white; max-height:400px; overflow-x: hidden; overflow-y: auto;
li, .eac-category { display: block;
&.selected { cursor: pointer; }
div { display: block; font-weight: normal; word-break: break-word; }
@alimoshen
alimoshen / form.html
Created January 30, 2018 16:53
Easy Autocomplete Form
<div>
<h2>Find a profile</h2>
<form class="searchProfile" action="#" method="post">
<input class="form-control searchField" id="profileFinder" name="profileFinder">
</form>
</div>
@alimoshen
alimoshen / easy-autocomplete-script.js
Last active January 30, 2018 16:51
Profile listing using easyAutocomplete
//Easy Autocomplete Options
var options = {
url: "datafeed.json",
getValue: "searchfield",
list: {
match: { enabled: true },
onShowListEvent: function() {
$("input[name='profileFinder']").on("input", mark);
}
},
@alimoshen
alimoshen / functions.php
Created January 29, 2018 23:29
Custom Rewrite rules
add_filter('rewrite_rules_array', 'mmp_rewrite_rules');
function mmp_rewrite_rules($rules) {
$newRules = array();
$newRules['expertise/(.+)/(.+)/(.+)/(.+)/(.+)/?$'] = 'index.php?expertise=$matches[5]'; // use the 5th tax segment
$newRules['expertise/(.+)/(.+)/(.+)/(.+)/?$'] = 'index.php?expertise=$matches[4]'; // use the 4th tax segment
$newRules['expertise/(.+)/(.+)/(.+)/?$'] = 'index.php?expertise=$matches[3]'; // use the 3rd tax segment
$newRules['expertise/(.+)/(.+)/?$'] = 'index.php?expertise=$matches[2]'; // use the 2nd tax segment
$newRules['expertise/(.+)/(.+)/?$'] = 'index.php?expertise_type=$matches[2]';
$newRules['expertise/(.+)/?$'] = 'index.php?expertise_type=$matches[1]';
return array_merge($newRules, $rules);
function get_taxonomy_parents($id, $taxonomy, $link = false, $separator = '/', $nicename = false, $visited = array()) {
$chain = '';
$parent = &get_term($id, $taxonomy);
if (is_wp_error($parent)) {
return $parent;
}
if ($nicename)
$name = $parent -> slug;
@alimoshen
alimoshen / functions.php
Created January 29, 2018 23:25
Get all terms
function filter_post_type_link($link, $post)
{
if ($post->post_type != 'expertise')
return $link;
if ($cats = get_the_terms($post->ID, 'expertise_type'))
{
$link = str_replace('%expertise_type%', get_taxonomy_parents(array_pop($cats)->term_id, 'expertise_type', false, '/', true), $link); // see custom function defined below
}
return $link;
}
@alimoshen
alimoshen / custom-taxonomy.php
Created January 29, 2018 23:23
Register Taxonomy
add_action( 'init', 'create_expertise_type_taxonomies', 0 );
function create_expertise_type_taxonomies()
{
// Add new taxonomy, make it hierarchical => true for categories-like taxonomies)
$labels = array(
'name' => _x( 'Expertise', 'taxonomy general name' ),
'singular_name' => _x( 'Expertise', 'taxonomy singular name' ),
'search_items' => __( 'Search Expertise' ),
'all_items' => __( 'All Expertises' ),
@alimoshen
alimoshen / post-profiles.php
Last active January 29, 2018 14:54
WordPress query exclude custom field value and when it doesn't exist
$query = array(
'post_type' => 'profiles',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'disable_profile',
'compare' => '==',
'value' => 'disabled',
),
array(