• Resolved Nox

    (@profnox)


    Hi,

    I wonder if it is possible to create a new CPT only in order to manage and use some fields and call this content on several templates of page : which mean that the CPT is totally hidden for the user (no url, no archive, nothing, just an interface for the admin and the possibility to loop on the content).

    It is difficult to explain so I will make an exemple. I need to display partners logos on my website on several pages, those partners are subject to change. so I wanted to create a CPT “Partners” with only two ACF fields (logo and label) to manage them easily. After that, I created a function which find all partners and display for each the logo and the label in a slide.

    But I don’t want the user to be capable of reaching a Partners page (which will be natively managed by the “single.php” file of WordPress) by following the slug or something like “mywebsite.com/partners/partner1/”. So this CPT is not intended to be shown in a page which belongs to it.

    Is there any way to do it ?

    Thank you in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • It’s definitely possible. When registering the post type you just need to set the public argument to false. Then it won’t be accessible from the front-end, but you can still use functions to use the data on the front-end if you wish.

    Thread Starter Nox

    (@profnox)

    Hi,

    Thank you for the fast answer. My bad, I already tried that, but my CPT disappeared from my admin menu when I did that. I though it was an argument to entierly disable the CPT (without delete it). Is there a way to take it back in the admin menu and still keep the “public: false” state ?

    Edit : Finally used thoses args, seems to work.

            'public'              => true,
            'has_archive'         => false,
            'exclude_from_search' => true,
            'publicly_queryable'  => false,
    • This reply was modified 6 years, 8 months ago by Nox.
    • This reply was modified 6 years, 8 months ago by Nox.
    • This reply was modified 6 years, 8 months ago by Nox.
    • This reply was modified 6 years, 8 months ago by Nox.
    • This reply was modified 6 years, 8 months ago by Nox.

    I should’ve mentioned: make sure show_ui is also set to true. From the documentation:

    ‘show_ui’
    (bool) Whether to generate and allow a UI for managing this post type in the admin. Default is value of $public.

    So if public is false, make sure to specify that show_ui is true. Make sure to read over that link and check what the default values for arguments are, and whether they are based on the value of other arguments, just in case you need to specify them.

    Just to be complete in the answer, menu_items are done this way, and attachments are very similar. There are also CPTs for custom_css and customizer_changesets.

    Thread Starter Nox

    (@profnox)

    Indeed, it seems to work fine with the ‘show-ui’ argument.
    Thank to both of you for your help

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Create unreachable CPT (only content management)’ is closed to new replies.