Skip to content

Instantly share code, notes, and snippets.

View alordiel's full-sized avatar
🛶
Požuri polako

a.vasilev alordiel

🛶
Požuri polako
View GitHub Profile
@alordiel
alordiel / get_list_of_posts.php
Last active June 6, 2017 12:02
WP PHP: build an array of post id => post title pairs by CPT
/**
* Function to query a given post type and to build array of the avialable titles. Used for select lists
* Used by:
*
* @param string $post_type Post type
* @return array $pairs Associative array with key[post id] and value[post title]
*/
function get_post_type_list_of_posts($post_type){
$pairs = array();
@alordiel
alordiel / array-used-in-replace.js
Created June 1, 2017 08:32
JS: using array of elements to seach and array of element for replace in standard replace function
var search = ['Á','Â','Á','Ã','É','Ê','Í','Ó','Ô','Õ','Ú','Ç','á','â','ã','é','ê','í','ó','ô','õ','ú','ç','À','à']
var replace= ['a','a','a','a','e','e','i','o','o','o','u','c','a','a','a','e','e','i','o','o','o','u','c','a','a'];
var string = 'Ele eé um homem';
for (var i = 0; search.length > i; i++) {
if (string.indexOf(search[i]) != -1) {
string = string.replace(search[i],replace[i]);
}
}
@alordiel
alordiel / add_login_logout_link_to_menu.php
Created May 25, 2017 07:37
WP PHP - function to append login/logut element to the end of navigation menu
@alordiel
alordiel / scrollToSelector.js
Created May 25, 2017 06:45
JS - scroll to top function that accepts selector element for offset from top
function scrollToPlace(selector,scrollTime,additionalToOffset) {
jQuery('html, body').animate({
scrollTop: jQuery(selector).offset().top - additionalToOffset
}, scrollTime);
}
@alordiel
alordiel / isJson.js
Created May 25, 2017 06:01
Short JS function for checking if a string is JSON ready
function IsJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
@alordiel
alordiel / default-function-parameters.js
Last active May 24, 2017 07:11
Passing default values to JS function
function x(a,b){
a = a || 10;
b = b || 12;
console.log(a);
console.log(b);
}
x();
// 10