Skip to content

Instantly share code, notes, and snippets.

View rayrutjes's full-sized avatar
🎸

Raymond Rutjes rayrutjes

🎸
View GitHub Profile
@rayrutjes
rayrutjes / algolia-wp-search-on-tags.php
Created July 26, 2016 16:09
Include post tags in the searching - Algolia Search for Wordpress
<?php
function custom_posts_index_settings( array $settings ) {
$settings['attributesToIndex'][] = 'unordered(taxonomy_post_tag)';
return $settings;
}
add_filter( 'algolia_posts_index_settings', 'custom_posts_index_settings' );
@rayrutjes
rayrutjes / algolia-number-synonyms.js
Created July 28, 2016 10:12
Generate number synonyms for Algolia. Run `node` algolia-number-synonyms.js
// @see number to string, pluginized from http://stackoverflow.com/questions/5529934/javascript-numbers-to-words
// @see http://stackoverflow.com/questions/20425771/how-to-replace-1-with-first-2-with-second-3-with-third-etc
const convert = function (num) {
return num2str.convert(num);
}
const num2str = {}
num2str.ones=['','one','two','three','four','five','six','seven','eight','nine'];
num2str.tens=['','','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety'];
@rayrutjes
rayrutjes / algolia-support.js
Created August 19, 2016 12:13
Quick script to test calls to Algolia indices.
#!/usr/bin/env node
var algoliasearch = require('algoliasearch');
const APP_ID = 'whatever';
const API_KEY = 'whatever';
const INDEX_NAME = "test";
var client = algoliasearch(APP_ID, API_KEY);
var index = client.initIndex(INDEX_NAME);
@rayrutjes
rayrutjes / search-by-algolia-for-woocommerce.php
Created September 23, 2016 11:14
This is a boilerplate for using Algolia in WooCommerce
<?php
/**
* @wordpress-plugin
* Plugin Name: Search by Algolia for WooCommerce - Instant & Relevant results
*/
/**
* If Algolia is not active, let users know.
@rayrutjes
rayrutjes / wordpress-svn-git-sync.md
Last active September 27, 2016 08:33
Some steps to kickstart the svn / git sync for WordPress plugins

Create an empty git branch

$ git checkout --orphan svn

checkout empty svn repository of the plugin

$ svn co https://plugins.svn.wordpress.org/search-by-algolia-instant-relevant-results/ .
search.addWidget({
init: function() {
$('.clear-search-icon').on('click', function() {
search.helper.setQuery('');
search.helper.search();
});
},
render: function(results) {
var clearIcon = $('.clear-search-icon');
if(results.state.query.length === 0) {
@rayrutjes
rayrutjes / different-backend-and-frontend-url.php
Created December 12, 2016 12:31
This gist is useful for the Algolia plugin for WordPress when the backend URL is different from the frontend URL.
<?php
/**
* @param array $shared_attributes
*
* @return array
*/
function custom_post_shared_attributes( array $shared_attributes) {
$shared_attributes['permalink'] = str_replace( 'cms.', 'www.', $shared_attributes['permalink'] );
@rayrutjes
rayrutjes / different-backend-and-frontend-url.php
Created December 12, 2016 12:32
This gist is useful for the Algolia plugin for WordPress when the backend URL is different from the frontend URL. Here we replace the `cms.` subdomain with the `www.` subdomain. After integrating this snippet in your code, you should trigger a full re-index.
<?php
/**
* @param array $shared_attributes
*
* @return array
*/
function custom_post_shared_attributes( array $shared_attributes ) {
$shared_attributes['permalink'] = str_replace( 'cms.', 'www.', $shared_attributes['permalink'] );
@rayrutjes
rayrutjes / instansearch-wpml.js
Created December 12, 2016 18:25
Filter instantsearch.js results based on current wpml language
/* global instantsearch */
var search = instantsearch({
// ...
searchParameters: {
filters: 'wpml.language_code:"' + icl_lang + '"'
}
// ...
});
@rayrutjes
rayrutjes / remove-sorting-option-woocommerce.php
Created January 4, 2017 18:32
Remove sorting options from WooCommerce
<?php
add_filter( 'woocommerce_catalog_orderby', function( $wc_options ) {
$remove_sort_options = array(
'popularity',
'rating',
'date',
'price',
'price-desc',
);