Generate Alpha Numeric number

Some times you want to generate Alpha Numeric , Numeric or Alphabetic digit for password or some kind of number. It can be 2 to 16 digit. For these problem i have a solutions:

function generateId($length, $type = 'ALPHANUMERIC') {

if($type == 'ALPHANUMERIC')
$chars = "12345CDEFGHI67890NOPQRSTU01492VWXYZ43210XYZFGH98765ABCDEF83574GHIJKLM09876QRSTUV54321";
else if($type == 'NUMERIC')
$chars = "1234567890987654321678905432101928374651029384756162738495061728394055432167890";
$id = "";
while (strlen($id)<$length) {
$id .= $chars{mt_rand(0,strlen($chars))};

return $id;


generateId(12,  'ALPHANUMERIC');

How to get post details by post id

get_post retrieve post data by post id. This is wordpress function with 3 parameters.

<?php get_post( $id, $output, $filter ); ?> 

$id : Here you will pass id of the post you would like to get data.
$output : This is optional value. Default value is OBJECT
OBJECT – (default) returns a WP_Post object
ARRAY_A – Returns an associative array of field names to values
ARRAY_N – returns a numeric array of field values
$filter: This is also an optional. It filter the post.


$showpost=get_post( 2 );