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
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?
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.
Hi
I just noticed that same thing is happening with custom taxonomies. I can't get the list of custom taxonomies using
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);
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.