Skip Navigation

[Resolved] How to get a list of all post types on my install?

This thread is resolved. Here is a description of the problem and solution.

Problem

How can I get a list of all Post Types that are registered on my site, and output it visually?

Solution

Toolset Post Types are stored in the WordPress native "posts" table.
Please refer to the WordPress Codex how to get a list of all post types registered.

This support ticket is created 6 years, 10 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by Beda 6 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#621656
toolset-support.png

Tell us what you are trying to do?
I have created custom post types
-1 Registration
-2 Redemption
Registration post type has multiple registration posts and Redemption post type have multiple redemptions posts. Now I am trying to get the list of all builtIn (post, page etc) and custom post types(Not the actual posts).

Is there any documentation that you are following?

Documentation: https://codex.wordpress.org/Function_Reference/get_post_types
$args = array('public' => true,'_builtin' => false); // expected to get custom post types
foreach ( get_post_types( $args, 'names' ) as $post_type ) {
var_dump($post_type);
}
But it's not returning the type registration or redemption.

Is there a similar example that we can see?
see the attached image

What is the link to your site?
On my local system

#621699

Then either of the $args does not match your Post Type.

Each Post Type created by Toolset Types will have '_builtin' => false, but it may have 'public' => true/false.

When you create or edit the Post Type in Toolset > Post Types you will see that there you can also set "Options", where such arguments are controlled.

I tested locally with my post types and the results are correct.

The sample code from WordPress itself is used:
https://codex.wordpress.org/Function_Reference/get_post_types

$args = array(
   'public'   => true,
   '_builtin' => false
);

$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'

$post_types = get_post_types( $args, $output, $operator ); 

foreach ( $post_types  as $post_type ) {
    echo '<p>' . $post_type . '</p>';
}

I think your post types are not public or elsehow modified to not match the query.

Doesn't my code snippet work in your install?

If so, where exactly do you load it?

#622319

I just used your code but it does not work. I double checked the settings of custom post type i.e. public. I have attached the screenshot of post type setting page.
P.S: Please ignore the error notification in screenshot, Its showing because we are using echo in code.

#622336

Hi
I just noticed that same thing is happening with custom taxonomies. I can't get the list of custom taxonomies using

get_taxonomies();

but than I looked into toolset types code and found that the following code can get the list of all taxonomies. Please take a look into the given code snippet.

// Read Types taxonomies first.
        $types_taxonomies = get_option( WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array() );
        var_dump($types_taxonomies);
        if ( is_array( $types_taxonomies ) ) {
            foreach ( $types_taxonomies as $slug => $data ) {
                $taxonomies[ $slug ] = $data;
            }
        }

        var_dump($taxonomies);
#622525

OK, the issue opened here is "how to get all post types".

You get all post types with this code:

$args = array(
   'public'   => true,
   '_builtin' => false
);
 
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
 
$post_types = get_post_types( $args, $output, $operator ); 
 
foreach ( $post_types  as $post_type ) {
    echo '<p>' . $post_type . '</p>';
}

I tested this.

If this does not work on your install this means it's an exception and we need to investigate what is happening.

Please provide me with a copy of this site.
https://toolset.com/faq/provide-supporters-copy-site/

Then I can dig into this and find the cause/solution

Please first try if the issue also persists with a WordPress Default Theme and NO Plugins BUT the Toolset Plugins?

If not, could you then re-enable the Plugins one after the other, and check the issue each time you enable a plugin?
Please report me when the issue comes back
It might also be due to the Theme.
Please do reactivate your Theme only after you are sure the issue isn't coming from a 3rd Party Plugin.

Thank you.