Skip to content

Instantly share code, notes, and snippets.

@CaroManel
CaroManel / 0_reuse_code.js
Last active August 29, 2015 14:23
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@CaroManel
CaroManel / ms-wp-changing-url.sql
Last active January 14, 2016 05:59
Change url in wordpress when migrating a site
SET @old := 'http://oldsite.carol.local';
SET @chunk_old := '%oldsite.carol%';
SET @new := 'http://mynewsite.carol.local';
UPDATE wp_options SET option_value = replace(option_value, @old, @new);
UPDATE wp_posts SET guid = replace(guid, @old, @new);
UPDATE wp_posts SET post_content = replace(post_content, @old, @new);
UPDATE wp_postmeta SET meta_value = replace(meta_value,@old, @new);
@CaroManel
CaroManel / wp-remove-slider-revolution-metabox.php
Created January 7, 2016 20:13
Remove Slider Revolution Metabox
/**
* Remove Slider Revolution Metabox
* for certain post types
*/
function remove_slider_rev_metabox() {
if ( is_admin() ) {
$post_types = array('page','post','custom','acf');
foreach ($post_types as $post_type) {
remove_meta_box( 'mymetabox_revslider_0', $post_type, 'normal' );
}
@CaroManel
CaroManel / wp-quick-installation
Created January 14, 2016 04:59
Quick Wordpress installation,
#!/bin/sh
#
# Quick WP installation
#
# Getting last version of WP
wget --quiet http://wordpress.org/latest.zip;
#unzip quietly
unzip -q latest.zip;
@CaroManel
CaroManel / wp-show-quieries.php
Created March 7, 2016 04:03
Show number of Wordpress querys and query strings on footer
function sc_profile() {
//only if we are debugging
if (WP_DEBUG === true) {
//only for administrators
if (current_user_can('level_10')) {
printf("%s queries in %s seconds.", get_num_queries(), timer_stop(0,3));
//show queries
@CaroManel
CaroManel / wp-exclude-uncategorized-posts-RSS.php
Created April 27, 2016 19:33
Remove uncategorized post from RSS feed
add_filter('pre_get_posts','exclude_category');
//exclude uncategorized category from rss
function exclude_category($query) {
if ( $query->is_feed ) {
$category_id = -1 * get_cat_ID('Uncategorized');
$query->set('cat', $category_id);
}
return $query;
}
@CaroManel
CaroManel / wp-enables-taxonomy-support-to-pages.php
Created April 30, 2016 04:29
Enables taxonomy (categories) support to pages
//adding category support to pages
add_action('admin_init', 'ga_register_tax_for_pages');
function ga_register_tax_for_pages() {
register_taxonomy_for_object_type('category', 'page');
add_post_type_support('page', 'category');
}
@CaroManel
CaroManel / wp-change-pwd-mysql
Created February 15, 2017 17:07
Query that changes password for user id
UPDATE wp_users SET user_pass = MD5('mypwd') WHERE ID=1 LIMIT 1;
@CaroManel
CaroManel / git-reset-remote.sh
Created March 2, 2017 03:41
Reset remote git repository to delete all commits
rm -r .git
git init
(create files)
git add -A
git commit -m 'Initial commit'
git remote add origin <url>
git push --force --set-upstream origin master
@CaroManel
CaroManel / binarySeachRecursive.php
Created January 16, 2018 19:18
Binary Search Recursive
<?php
function binarySearchRecursion($array, $find, $left, $right)
{
if ($left > $right) {
return -1;
}
$middle = floor( ($left + $right) / 2 );
if ($find === $array[$middle]) {