Skip to content

Instantly share code, notes, and snippets.

View Irfan-Ansari's full-sized avatar

Irfan Ansari Irfan-Ansari

View GitHub Profile
@Irfan-Ansari
Irfan-Ansari / gist:8952066
Created February 12, 2014 08:54
Jquery Selector by data attributes
// Select by specific element type, attribute and value
$("div[data-myattr='myvalue']").doSomething();
// Select by specific element type and attribute
$("div[data-myattr]").doSomething();
// Select by specific attribute
$('[data-myattr]').doSomething();
// See more: http://api.jquery.com/contains-selector/
@Irfan-Ansari
Irfan-Ansari / Bubble css
Created February 19, 2014 23:09
Bubble css
.bubble {
position: relative;
height: 75px;
width: 100%;
border-radius: 5px;
margin-bottom: 20px;
}
.red.bubble {
background-color: pink;
}
@Irfan-Ansari
Irfan-Ansari / How to set path in wordpress
Created February 19, 2014 23:10
How to set path in wordpress
//Basics & WordPress Standards
$absolute_path = __FILE__;
$path_to_file = explode( 'wp-content', $absolute_path );
$path_to_wp = $path_to_file[0];
require_once( $path_to_wp.'/wp-load.php' );
@Irfan-Ansari
Irfan-Ansari / Get posts and group by taxonomy terms
Created February 19, 2014 23:11
Get posts and group by taxonomy terms
/**
* Get posts and group by taxonomy terms.
* @param string $posts Post type to get.
* @param string $terms Taxonomy to group by.
* @param integer $count How many post to show per taxonomy term.
*/
function list_posts_by_term( $posts, $terms, $count = -1 ) {
$tax_terms = get_terms( $terms, 'orderby=name');
foreach ( $tax_terms as $term ) {
echo '<h2>' . $term->name . '</h2> <ul>';
@Irfan-Ansari
Irfan-Ansari / get_post_id_by_meta_key_and_value
Created February 19, 2014 23:12
get_post_id_by_meta_key_and_value
<?php
if (!function_exists('get_post_id_by_meta_key_and_value')) {
/**
* Get post id from meta key and value
* @param string $key
* @param mixed $value
* @return int|bool
*/
function get_post_id_by_meta_key_and_value($key, $value) {
var app = app || {};
//object literal
app = {
init: function(){
this.cache();
this.bind();
},
cache: function(){
this.anchor = $( 'a' );
@Irfan-Ansari
Irfan-Ansari / remove menu (page, post etc ) from wordpress admin menu
Created March 12, 2014 10:09
remove menu (page, post etc ) from wordpress admin menu
<?php
function remove_menus(){
remove_menu_page( 'index.php' ); //Dashboard
remove_menu_page( 'edit.php' ); //Posts
remove_menu_page( 'upload.php' ); //Media
remove_menu_page( 'edit.php?post_type=page' ); //Pages
remove_menu_page( 'edit-comments.php' ); //Comments
remove_menu_page( 'themes.php' ); //Appearance
remove_menu_page( 'plugins.php' ); //Plugins
<?php
/**
* Merge multiple WP_Error objects together
*
* @return WP_Error
*/
function wp_error_merge() {
$wp_error_merged = new WP_Error();
$wp_errors = func_get_args();
jQuery( function( $ ) {
if ( 'undefined' === typeof FB )
return;
if ( $( 'body' ).hasClass( 'single-post' ) || $( 'body' ).hasClass( 'page' ) ) {
var $comments_div = $( '<div/>' );
$comments_div.addClass( 'fb-comments' );
$comments_div.attr( 'data-href', document.location );
$comments_div.appendTo( $( '.primary-content' ) );
<?php $query = new WP_Query( array( 'posts_per_page' => 100, 'fields' => 'ids' ) ); ?>
<?php if ( $query->have_posts() ) :
$post_ids = $query->posts;
shuffle( $post_ids );
$post_ids = array_splice( $post_ids, 0, 12 );
foreach ( $post_ids as $post_id ) :
$post = get_post( $post_id );
setup_postdata( $post );
?>