Skip Navigation

Query posts associated with a custom post type

This support ticket is created Il y a 8 années et 11 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 3 réponses, has 2 voix.

Last updated by Srdjan Il y a 8 années et 11 mois.

Assigned support staff: Srdjan.


I need to be able to query posts associated with a custom post type in php either in the typical wordpress manner or directly through MySQL. I need to do this because I need to get counts (and ids) of child posts associated with a custom post type for a shortcode I am writing. Can you please provide me some sample code on how to do this with php since in this case I won't be doing this through a View?

I have a custom post type named Courses which has generic Posts as its children. I need to be able to get a list of Course ids and I need to be able to get the list of post ids that are the children of a particular Course so I can do other lookups with those ids.



Dear Diego,
there is API call

types_child_posts( $post_type, $args )

It will fetch child posts for current post (global $post).
Recently we added support to specify post ID using


and it will be included in next release.

This function will return array of post objects together with Types custom fields associated to them.

If you need call that will use less resources (just to get IDs of children),
you should query posts that have custom field and value like this:

'meta_key' => "_wpcf_belongs_{$parent_post_type}_id",
            'meta_value' => $parent_post_id

Please tell me if this helps.


That sounds great. When will the next release be? Is there something else I can do in the meantime to have that functionality now? Perhaps query the wordpress tables directly?


Types are going through pre-release tests, it will be out very soon.
Maybe it's better to query WP tables directly if you are sure that there will be a lot of posts to query,
or use WP meta query

Le sujet ‘Query posts associated with a custom post type’ est fermé à de nouvelles réponses.