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 answer:

$program_fee = types_child_posts('donation-amount', array('post_id' => $program_id));

Until I dig into the code would I find that they have a second parameter that would accept an array called"post_id".

In short, types_child_posts works SIMILAR to get_posts.  But to get your problem solved, the above code should do it.

If you are interested in what other parameters this function accepts, go to the plugin and look at the code, you will find it.

Again, unfortunately official documentation did not say it clearly, until developer goes to find their code...

Comments

Popular posts from this blog

TCPDF How to show/display Chinese Character?

Wordpress Load balancing: 2 web servers 1 MySQL without any Cloud services

Using wget bypass htaccess username password 401 authorization