Skip to content

Instantly share code, notes, and snippets.

View hchouhan's full-sized avatar
💡
Thinking

Harish Chouhan hchouhan

💡
Thinking
View GitHub Profile
@hchouhan
hchouhan / gist:5180348
Created March 17, 2013 06:09
I Recommend This Plugin Code.
<?php
/**
* Plugin Name: I Recommend This
* Plugin URI: http://www.harishchouhan.com/personal-projects/i-recommend-this/
* Description: This plugin allows your visitors to simply recommend or like your posts instead of commment it.
* Version: 2.1.3
* Author: Harish Chouhan
* Author URI: http://www.harishchouhan.com
* Author Email: me@harishchouhan.com
*
@hchouhan
hchouhan / html5.sublime-snippet
Last active December 16, 2015 01:09
HTML5 Template for Sublime Text 2
<snippet>
<content><![CDATA[<!DOCTYPE html>
<!--[if IE 7 ]><html id="ie7" lang="en"><![endif]-->
<!--[if IE 8 ]><html id="ie8" lang="en"><![endif]-->
<!--[if IE 9 ]><html id="ie9" lang="en"><![endif]-->
<!-- BEGIN html -->
<html lang="en">
<!-- BEGIN head -->
<head>
@hchouhan
hchouhan / gist:5560808
Created May 11, 2013 17:55
Freshdesk for WordPress plugin
<?php
/*
* Plugin Name: Freshdesk
* Plugin URI: http://www.harishchouhan.com/wordpress-plugins/freshdesk/
* Description: Allows you to setup single sign on capabilities between your site and Freshdesk. Create's user accounts on the fly, automatically logs in users.
* Version: 1.1
* Author: Harish Chouhan
* Author URI: http://www.harishchouhan.com/
* Author Email: hello@dreamsmedia.in
* License: GPLv2
@hchouhan
hchouhan / gist:6273438
Created August 19, 2013 20:04
Get Link to just 1 category in which the current post/product is in. dot_browse_product_cat()
<?php
// get taxonomies terms links
function dot_browse_product_cat() {
global $post, $post_id;
// get post by post id
$post = &get_post($post->ID);
// get post type by post
$post_type = $post->post_type;
// get post type taxonomies
$taxonomies = get_object_taxonomies($post_type);
@hchouhan
hchouhan / gist:6538693
Created September 12, 2013 14:46
Restrict Admin Area To Only Admin Users
function restrict_admin()
{
if ( ! current_user_can( 'manage_options' ) ) {
wp_redirect( site_url() );
exit;
}
}
add_action( 'admin_init', 'restrict_admin', 1 );
@hchouhan
hchouhan / gist:6554166
Created September 13, 2013 18:16
Display Author Avatar In Post
<?php
// echo get_avatar( $id_or_email, $size, $default, $alt );
echo get_avatar( get_the_author_email(), '128', '/images/no_images.jpg', get_the_author() );
?>
@hchouhan
hchouhan / gist:6727356
Last active December 24, 2015 01:59
IRT raw Query
<?php
function dot_most_recommended_posts($numberOf, $before, $after, $show_count, $post_type="showcase" ) {
global $wpdb;
$request = "SELECT * FROM $wpdb->posts, $wpdb->postmeta";
$request .= " WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id";
$request .= " AND post_status='publish' AND post_type='$post_type' AND meta_key='_recommended'";
$request .= " ORDER BY $wpdb->postmeta.meta_value+0 DESC LIMIT $numberOf";
$posts = $wpdb->get_results($request);
@hchouhan
hchouhan / gist:6727363
Created September 27, 2013 11:43
IRT - Updated code
<?php
$query_top_10_showcase = new WP_Query(
array(
'post_type' => array( 'showcase' ),
'orderby' => 'meta_value',
'meta_key' => '_recommended',
'paged' => $paged
)
);
@hchouhan
hchouhan / OnePageMania
Last active December 24, 2015 02:19
OnePageMania
<?php
$query_top_10_posts = new WP_Query(
array(
'post_type' => array( 'post' ),
'post_status' => 'publish',
'orderby' => 'meta_value_num',
'meta_key' => '_recommended',
'posts_per_page' => 10,
'nopaging' => false
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(