Make WordPress Core

Opened 7 years ago

Last modified 6 years ago

#18958 closed defect (bug)

Can't set "Show on screen" for Custom post types — at Version 8

Reported by: dd32 Owned by:
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.3
Component: Administration Keywords: has-patch early
Focuses: Cc:

Description (last modified by dd32)

As above. The posts_per_page "show on screen" function on custom post pages doesn't apply/save.

Change History (10)

#1 @ryan
7 years ago

Seems okay here. What's the CPT name? Maybe the switch to sanitize_key() busted something.

Last edited 7 years ago by ryan (previous) (diff)

#2 @nacin
7 years ago

  • Keywords reporter-feedback added; needs-patch removed

#3 follow-up: @SergeyBiryukov
7 years ago

With the "Book" CPT example from Codex, my results are a bit different.

On initial page load, all meta boxes are displayed, but only "Featured Image" is checked in "Show on screen" (see the screenshot). If I toggle the checkboxes, the changes seem to be applied correctly.

#4 in reply to: ↑ 3 @SergeyBiryukov
7 years ago

Replying to SergeyBiryukov:

On initial page load...

i.e. when there's no metaboxhidden_book record in wp_usermeta.

Happens in 3.2.1 as well.

#5 @SergeyBiryukov
7 years ago

Being called from meta_box_prefs() and do_meta_boxes(), get_hidden_meta_boxes() returns different results, due to different $screen values.

In meta_box_prefs(), it's:

WP_Screen Object( [id] => book, [base] => post, ... )

In do_meta_boxes(), it's:

stdClass Object( [id] => book, [base] => book )

Note the difference in base value.

Not sure what the preferred option is, but 18958.patch at least makes it consistent.

#6 @dd32
7 years ago

Ok so.. I'm shamed to say: I was using a CPT plugin to add the post type. Below is the call it's using, It's probably caused by the dash in the CPT name, in core we underscores, I'd say it's messing with the splitting on dashes which I believe the screen options stuff uses.

register_post_type('test-cpt', array(
  'label' => 'Test CPT',
  'description' => '',
  'public' => true,
  'show_ui' => true,
  'show_in_menu' => true,
  'capability_type' => 'post',
  'hierarchical' => true,
  'rewrite' => true,
  'query_var' => true,
  'has_archive' => true,
  'supports' => array('title','editor','excerpt','custom-fields','comments','revisions','page-attributes')

#7 @SergeyBiryukov
7 years ago

With this code, "Show on screen" also seems to work for me in current trunk (aside from the initial checkboxes inconsistency I've mentioned). The meta key saved is metaboxhidden_test-cpt.

Last edited 7 years ago by SergeyBiryukov (previous) (diff)

#8 @dd32
7 years ago

  • Description modified (diff)

Oh damn, Sorry I've missed one very important word in the original ticket, The posts per page field doesn't save.

Note: See TracTickets for help on using tickets.