Skip to content

Instantly share code, notes, and snippets.

View easyAutocomplete.js
/*
* 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 Jan 30, 2018
Easy Autocomplete Profile Styling
View profile-autocomplete.scss
.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 Jan 30, 2018
Easy Autocomplete Form
View form.html
<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 Jan 30, 2018
Profile listing using easyAutocomplete
View easy-autocomplete-script.js
//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 Jan 29, 2018
Custom Rewrite rules
View functions.php
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);
View functions.php
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;
View functions.php
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;
}
View custom-taxonomy.php
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-type.php
Created Jan 29, 2018
Custom post type registration
View post-type.php
// Post type 'expertise'
add_action( 'init', 'create_expertise_post_type', 4 );
function create_expertise_post_type()
{
$labels = array(
'name' => __( 'Expertise' ),
'singular_name' => __( 'Expertise' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Create New' ),
'edit' => __( 'Edit' ),
@alimoshen
alimoshen / post-profiles.php
Last active Jan 29, 2018
WordPress query exclude custom field value and when it doesn't exist
View post-profiles.php
$query = array(
'post_type' => 'profiles',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'disable_profile',
'compare' => '==',
'value' => 'disabled',
),
array(