I use a plugin that generates some custom post types, such as 'ctp_1' ctp_2' etc...

I also use a form plugin with a post management feature that allows me to either create or update posts throught this form.

However it's not able to fetch custom post type created by this plugin since they're hidden, just post, pages or custom and ACF post types

I tried to expose them with this code, but wasn't able to have it worked

function custom_modifica_post_type() {
global $wp_post_types;

// List of hidden post types
$custom_post_types = ['cpt_1', 'cpt_2'];

foreach ($custom_post_types as $post_type) {
    if (isset($wp_post_types[$post_type])) {
        // Rendi il post type pubblico
        $wp_post_types[$post_type]->public = true;
        $wp_post_types[$post_type]->publicly_queryable = true;
        $wp_post_types[$post_type]->show_ui = true;
        $wp_post_types[$post_type]->show_in_nav_menus = true;
        $wp_post_types[$post_type]->show_in_admin_bar = true;
add_action('init', 'custom_modifica_post_type');

Any thoughts on that?

  • can you provide information about the form itself? What is the plugin that creates the CPTs? Note that fixing the code you shared will depend entirely on which plugin you chose, this is unlikely to be something you can fix in a generic way, e.g. your code might not have worked because of when and how the plugin registers the post type, and your problem with the form might have nothing to do with its registration, naming the plugins is unavoidable. Note also that 3rd party plugins are offtopic here, there's a very high chance this question isn't allowed
    – Tom J Nowell
    Nov 29, 2023 at 15:01


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.