Posts by wp-admin

WordPress Themes Comments Off

WordPress Themes

Posted by on Sep 9, 2014 in product

WordPress Themes are files that work together to create the design and functionality of a WordPress site. Each Theme may be different, offering many choices for site owners to instantly change their website look.

Learn More
Joomla Templates Comments Off

Joomla Templates

Posted by on Sep 9, 2014 in product

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

Learn More

WordPress meta queries

Posted by on Sep 9, 2014 in blg

If you want to get a post with meta key show_on_homepage and meta value on, you can do it in the following way:

$rd_args = array(
	'meta_key' => 'show_on_homepage',
	'meta_value' => 'on'
);

$rd_query = new WP_Query($rd_args);

If you need to query all posts except the ones with this pair of meta key and value, you can use the following parameters:

$rd_args = array(
	'meta_key' => 'show_on_homepage',
	'meta_value' => 'on',
	'meta_compare' => '!='
);

$rd_query = new WP_Query( $rd_args );

Get Posts with a Specific Custom Field Value

// the meta_key 'color' with the meta_value 'white'
$rd_args = array(
	'meta_query' => array(
		array(
			'key' => 'color',
			'value' => 'white'
		)
	)
); 
$rd_query = new WP_Query( $rd_args );

Get all the posts except the ones with meta key «color» and meta value «white»:

$rd_args = array(
	'meta_query' => array(
		array(
			'key' => 'color',
			'value' => 'white',
			'compare' => '!='
		)
	)
);

$rd_query = new WP_Query( $rd_args );

Get all the posts with white OR green color custom field value:

// custom field name is color and custom field value is 'white' OR 'green'
$rd_args = array(
	'meta_query' => array(
		array(
			'key' => 'color',
			'value' => array('white','green'),
			'compare' => 'IN'
		)
	)
); 
$rd_query = new WP_Query( $rd_args );

Get all the posts (products in online shop for example) except white products and green products:

$rd_args = array(
	'meta_query' => array(
		array(
			'key' => 'color',
			'value' => array('white','green'),
			'compare' => 'NOT IN'
		)
	)
);
$rd_query = new WP_Query( $rd_args );

Get Posts Within a Given Range of Numeric Meta Values

// the product price is more than 2000 and less than 4000
$rd_args = array(
	'meta_query' => array(
		array(
			'key' => 'price',
			'value' => array( 2000, 4000 ),
			'type' => 'numeric',
			'compare' => 'BETWEEN'
		)
	)
);
$rd_query = new WP_Query( $rd_args );

Numeric Comparison

$rd_args = array(
	'meta_query' => array(
		array(
			'key' => 'price',
			'value' => 2000,
			'type' => 'numeric',
			'compare' => '>='
		)
	)
);
The product price is less than 4000:
$rd_args = array(
	'meta_query' => array(
		array(
			'key' => 'price',
			'value' => 4000,
			'type' => 'numeric',
			'compare' => '<'
		)
	)
); 
$rd_query = new WP_Query( $rd_args );

Query Posts by Several (two or more) Custom Field Values

$rd_args = array(
	'meta_query' => array(
		'relation' => 'AND',
		array(
			'key' => 'color',
			'value' => 'white'
		),
		array(
			'key' => 'price',
			'value' => array( 2000, 4000 ),
			'type' => 'numeric',
			'compare' => 'BETWEEN'
		)
	)
); 
$rd_query = new WP_Query( $rd_args );
Learn More

WordPress Hacks

Posted by on Sep 9, 2014 in blg

Here are few wordpres hacks that are very usefull while developing wordpress plugins and themes.

Hide wordpress adminbar

add_action('init', 'remove_admin_bar');
function remove_admin_bar() {
if ( !current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}

Show user/author posts only in admin

By default wordpress displays all posts for any user logged into wp-admin. The following code restricts the post list by displaying only his posts.

function wps_get_post_list_by_user($clauses) {
if (is_admin()) {
global $user_ID, $wpdb;
// $clauses['join'] = ", wp_posts";

$clauses['where'] .= " AND wp_posts.post_author = ".$user_ID;

};
return $clauses;
};
if ( !current_user_can( 'edit_users' ) ) {
add_filter('posts_clauses', 'wps_get_post_list_by_user');
}

Remove unwanted admin menus

function remove_admin_menu_items() {
$remove_menu_items = array(__('Links'), __('Dashboard'),  __('Media'), __('Links'), __('Appearance'), __('Tools'),  __('Settings'), __('Comments'), );
global $menu;
end ($menu);
while (prev($menu)){
$item = explode(' ',$menu[key($menu)][0]);
if(in_array($item[0] != NULL?$item[0]:"" , $remove_menu_items)){
unset($menu[key($menu)]);}
}
}

if(get_logged_user_role()!="administrator"){
add_action('admin_menu', 'remove_admin_menu_items');
}

Set Post Expert Length

function custom_excerpt_length( $length ) {
	return 100;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

Hide Plugin Update Notifications

just copy and paste that code in the .php file of the plugin

add_filter('site_transient_update_plugins', 'dd_remove_update_nag');
function dd_remove_update_nag($value) {
 unset($value->response[ plugin_basename(__FILE__) ]);
 return $value;
}
Learn More