• Hey – I am curious if you can set a page for a custom post type index, like you do when you set the “Blog” page as the index for posts in the Setting > Reading.

    I don’t need the admin functionality just set page so I can use the ID to grab some setting used in a custom theme.

    • This topic was modified 7 years, 3 months ago by ebud.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s no mechanism to do that, but you can create a custom template for a specific custom post type page so it acts like an archive page. For example, make a template page that makes a query for all CPTs and lists the results, then name it following the format of single-{post-type}-{slug}.php. When this CPT page is requested, the template code is executed. This page is assigned an ID like any other and you can get settings on the template accordingly.

    But if all you need is a particular setting, if you know the page ID, you don’t need to actually request the page. You can get the setting at any time in any code by using it’s assigned ID regardless of the current request. Even if you don’t know the ID, the CPT page object could be queried using any arbitrary criteria with get_post(). The ID you seek is in the returned object. With the ID, get the associated setting.

    Thread Starter ebud

    (@ebud)

    Thanks!

    I think I will make a custom template that lists all the items in the custom post type. I don’t need a single post view so this should work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Set a page for custom-post-type index’ is closed to new replies.