Displaying only immediate children (only one level) pages in WordPress. For example, I have page and sub page structure like:
Let’s suppose, you need to list all children pages of Page 1, i.e. Page 11, Page 12, Page 13. But you don’t want to be listed Page 111, Page 112 and so on which is WordPress’s default behavior.
Let us assume that ID of Page 1 is 5 then:
$result = get_pages('child_of=5&hierarchical=0&parent=5);
Notice the child_of and parent must have same value. This function will get only three page – Page 11, Page 12, Page 13 and not Page 111, Page 112 and so on.
$refrence_id = 'DD'.mt_rand(100000, 999999);
// check if number already exists in database
$ref = mysql_query("select count(*) from registration where refrence_id='".$refrence_id."'");
$refer_no = mysql_fetch_array($ref);
if($refer_no > 0)
$tmpRefID = refrence_id();
There are several times when you need to display the age of the user on your website. There are two ways to do that:
- Add Date of Birth column as well as age column.
- Display age from the Date of Birth.
Taking both the field from the user doesn’t seems to be good enough, so what to do ?
Just add the following function and you get the age of the user from the Date of Birth.
return floor((time() - strtotime($birth_date))/31556926);
echo "I am ".get_age("1989-10-21") ." years old";
I am 23 years old.
You need to write Date of Birth in yyyy-mm-dd format which is the default database date format.