Showing posts from 2015

Wordpress (Custom) Post Type, Taxonomy, Tags, Term In One Image

I know that for wordpress beginner, it is quite difficult at first to understand the real relationship between (Custom) post type, taxonomy , tags, category, terms and so on.

Yes, I have been there and now I understand it.  That's why I create the below image to illustrate it all, in order to cut time to learn it from here, which is not very clear.  It would be very useful for people who write wordpress program also.
How to read it?
I use default value in wordpress and custom post type to illustrate the idea.
This image is read from left to right.  
The highlight doesn't mean anything, just to split it so that you can read it clearly only.

Post Type
Wordpress default post type includes, at least, post and page.  But post type is not limited to post and pages, it can also be other thing (known as "Custom Post Type").  Cars, Food, Sports and other thing can also be post type.

How To Structure? / Taxonomy and Term
Most of the people (Me included) failed on this part.

iOS push message using PHP - Success but push message not receive in iPhone

There are several things to check.  Ask yourself these questions:

Are you using correct device token?Are you successfully telnet/ping the push message server (start with ssl://)Did your network set to block outgoing connection to push message server?Did your network set to block getting device token?Are you using correct certificate? The last point is most critical: An app build using distribution cert WOULD NOT receive push message using development cert, and vice versa.
Make sure you are using correct cert when you are doing your test.
Hope it helps someone.

PHP Upload File Through REST: Using HTTP POST JSON data Return Blank Page

If you are:

Using REST API (XML RPC Hybrid, a.k.a. calling URL)Submit a large volumn of data (e.g. 10MB) through JSON base64 stringSubmit using HTTP POST to a URLGet a blank page (no return) after submitNo error log  Check these 3 things:
In your php.ini: upload_file_size has big enough value.  e.g. 10MB or 15MBpost_max_size has big enough value.  e.g. 10MB or 15MBmemory_limit has big enough value.  e.g. 128MB If you just changed the first two and still get blank page when you upload, chances are you have already exhausted your memory.  Raise your memory so as to make the page load.
It is particularly useful if you are using mobile service (iPhone, Android) to upload image to server using base64.  
Hope it helps someone.

[Solved] bbPress Chinese (Taiwan/China) language file not working!

OK.  Simply put:

If you are following this link about how to use bbPress in your language, and follow these two instruction:

How to use the language files Rename each file of the files to bbpress-language_COUNTRY.extension eg. bbpress-plugin-pt-br.po to bbpress-pt_BR.po
and to
Note: Ensure you use the - and _ in the correct place per the above example. Using FTP upload both the .po and .mo files to /wp-content/languages/bbpress/ of your WordPress instalation. If the /wp-content/languages/ and /wp-content/languages/bbpress/ folders do not exist, create them. In case you found yourself, like me, do the following, it WON"T WORK!


The correct name should be


Same thing for zh_CN
Hope it helps someone.

Wordpress Types plugin: How to get child custom field in parent custom field

Wordpress Types is actually a good plugin.  To certain extended it is much better than ACF (e.g. Types has a free "repeater" field but in ACF it is a paid function).

OK.  Today my problem is this:

- I created a custom field "Program" using WP Types (Types for short)
- I also have a custom field "Program Fee" that is a child of "Program".  (Why not taxonomy? Because "Program Fee" has multiple items and is different for different program.  In this case using "Custom Field" is better than "Taxonomy")

The way to do it is explained very clearly here , here and here.  (By the way, I got these 2 links from Google, not from their official site....)

Now the problem is: I want to get "Program Fee" from specific "Program".  i.e. getting all child custom field from a specific custom field...

Unfortunately, up to this moment, the official site did not have clear instruction on how to do that.

So here is the a…

List Of $1 Hosting Websites - 2015

List Of $1 Hosting Websites ttp://

How to split a huge size log file and only get what you want in Linux?

Today I encounter a task as follow:

I need to extract a 7.3GB Apache access log and ONLY grab the access log starting from 30 August and up to today.

I don't need to say it is non-sense to open a 7.3 GB file in a text editor, even in vi under linux, the RAM that is used is huge, and it just doesn't work that way.

So to solve this problem, here are the steps I took, thanks to the following reference:

Find out the exact string first occurrence in the log file and print the first 5 lines.  Actually I can only print one line but I just like 5:grep -n "30/Aug/2015" access_log | head -n 5The returned line will be:61445828: - - [30/Aug/2015:00:00:01 +0800] "GET <somewebsite>/index.htm HTTP/1.1" 200 10824The first item: 61445828 is the line numberCount the total number of lines in access log, and get the number:wc -l access_logThe return is: 64328208 access_log.oldNow,…

Types Fields API: How To Display Field For Specific Post?


One of my recent project is to use WP-Types to create certain custom post type and fields.
You can think of it as an alternative of Advanced Custom Field, but more options and functions.
My problem: I would like to display an image for a particular post. 
However, according to this link, it does not clearly said how to do it, even after reading the "Displaying Fields of Parent Pages"
And the following does not work: print types_render_field('cover-image-english', array(
"width" => 150,
"resize" => 'proportional',
"id" => $item_id,

Later on when I dig into the code, the actual parameter is "post_id", not "id", which is mentioned in the reference link.

And the following works:

print types_render_field('cover-image-english', array(
"width" => 150,
"resize" => 'proportional',

Pagelines - Editor Icon Image not show (only show rectangle) fix

Case study:

I am doing development in my local machine.  Once it is done, I am copying my site from local machine to another machine.
I copies all files to remote site, and copy all data from localhost MySQL to remote MySQL, with all domain information replaced using searchreplacedb2.php.
However, when you complete all these, you will see the following error:

failed to load resources (404): dms/fonts/fontawesome-webfont.woff2dms/fonts/fontawesome-webfont.woffdms/fonts/fontawesome-webfont.ttf If you digg into the problem, you will most often see this solution:
In .htaccess, add this line:
Header set Access-Control-Allow-Origin "*"
But to me, that doesn't work.  Because for some unknown reason, Pagelines in new server is referencing to a file in old server. How to fix? To fix this problem, look for this file:
In this file, it will load the fontawesome font file, which it incorrectly reference all font files to "localhost&q…

IIS 8.5 PHP Cannot Upload File - Permission Denied

If you have problem of not able to upload file and the error log said: permission denied/Unable to create file at line 0 (something like that), here is my suggestion:

Go to your IIS, right click your application and select: Edit PermissionIn the "Security" screen where you can select a list of users and set permission, try to find if you have a user group called IUSR or IIS_IUSR.If you don't have it, use "Add" to add them inAssign "Full control" for those two groups and click "OK"Now here comes to the crucial part: Since PHP will first upload your file to a temporary folder first, then copy the file from temp folder to destination folder.  THE TEMPORARY FOLDER MUST ALSO BE WRITABLE BY IIS!!!So find that temporary folder out, add permission in that folder to allow IUSR and IIS_IUSR to have "full control"That would be OK. Hope that helps someone.

Drupal 7 How to clear login cache after changing admin password

To people who are looking for way to login to drupal 7 after changing password of admin account with the following command:

php scripts\ <some password text>

Please login to your DB and find a table called:


and clear all the records inside.  You can refer to this post and under the section "Clear flood table" to find the description.

I tested it and it works!

Another way to do it is to repair <prefix>_session table, coming from this post.

Haven't tried that, and use it at your own risk.

Hope that helps someone.

Wordpress ERROR CONNECTION RESET Fix, Reinstall Wordpress

To people who are having the ERROR_CONNECTION_RESET problem when they are using Chrome to do wordpress development.

Occasionally developer may have problem above, but no clue how to solve it.

Actually, I don't know how to solve it either after doing all the Google search.

So the only valid method is to re-install Wordpress, but still keep database content (including all config values) exists.

Here is how I did, it works for me (My wordpress version is 4.1.1):

Download latest version of Wordpress and unzip for later useIn your existing wordpress installation, backup wp-content/ folder and wp-config.php by copying it into another placesRemove all existing wordpress files (make the whole directory empty)Copy all files from the latest copy of WP you just downloaded and place it into this empty folderRe-visit your WP site using a browser.  At this point you will be able to connect to the site, and require you to install WP.  Follow all the steps.At the end, the website will prompt to yo…

PHP Array to CSV in UTF-8 read by MS Excel

To people who are looking for a PHP script that can convert an array (mostly multi-dimensional array) to CSV in UTF-8, here is the code and file for you to download:

PHP Array To CSV Read By MS Excel in UTF-8

Credit to Jérôme Jaglale, what I am looking for is a CodeIgniter solution to convert array to CSV, but it can also be used in non-CI PHP application. This is not a class, just a function (Helper). The full code below:

if(!function_exists('array_to_csv')){ function array_to_csv($array, $download = ""){ // if(empty($download)){ $res = array(); foreach($array as $arr) { $res[] = implode(',', $arr); } return $res; }else{ $output = fopen("php://output",'w') or die("Can't open php://output"); // header('Content-Encoding:…

PHP陽曆轉陰曆(農曆),陰曆轉陽曆的方法/Western Calendar To Chinese Lunar Calendar

Reference: PHP阳历转阴历(农历),阴历转阳历的方法

Due to the recent project, we need a PHP function that convert a Western calendar to Chinese Lunar Calendar.

Upon searching on the web, we found the resource above (In Simplified Chinese) that demonstrate how to do the conversion.

But there is a limit: the range is from Year 1891 to 2100.

There is also a bug in the class that, when there is a leap month, the calculation on month will be wrong.

Fortunately I (think) I solve the problem by issuing a simple "If" statement.  The full source code can be downloaded here:

There is only 1 PHP file.  The class name is lunar.class.php

To use this class, follow the same instruction at the reference page, or here:

<?php header("Content-Type:text/html;charset=utf-8"); $lunar=new Lunar();// $month=$lunar->convertSolarToLunar(2013,07,08);//将阳历转换为阴历 echo '<pre>'; print_r($month);
Hope it helps…