Pages

Tuesday, January 24, 2012

Checking and prepending `http://` in a link

Sometimes users/site admins are required to submit some URL, e.g. Facebook fanpage url or Twitter URL - that is an outbound link.

But HTML anchor tag href attribute does not work properly without http:// at the beginning of the url string.

So, we should have a validity check. The below line can do the work and will add the http:// if user does not give it.

In PHP:

if( stristr( $url, 'http://' )===false ) $url = 'http://'.$url;

Monday, January 23, 2012

Wordpress: Ordering posts by Meta value

In the query_posts functions parameter, we need to add this:

meta_key=<KEY_NAME>&orderby=meta_value_number&order=DESC

Replace <KEY_NAME> the with your meta key name For example:


<?php query_posts( 'meta_key=<KEY_NAME>&orderby=meta_value_number&order=ASC' ); ?>


Order Could be ASC - Ascending or DESC - descending