Tagged: scope post, select
- This topic has 7 replies, 2 voices, and was last updated 5 years, 8 months ago by
Steve.
-
AuthorPosts
-
-
June 2, 2016 at 10:28 pm #6571
mcmasterMemberI have an event post type. Some events are small; others are annual events and warrant their own pages. So I have a select field for events that enables the user to choose the page associated with an event.
I’ve done this before with post_meta and had no problem. But this time, because the events aren’t hierarchical, I decided to use post_parent to store the page ID. What I found is that I could set the post_parent to have a specific page value, but that I couldn’t set it to zero.
When the value is stored in post_meta, there’s no problem setting it back to zero.
Here’s the code:
<?php /* Title: Page Test Description: select page for event Post Type: event Priority: high Order: 20 */ // get an array of page titles indexed by page IDs $default_page = array( 0 => '-- none --' ); $choices = $default_page + piklist( get_posts( array( 'post_type' => 'page', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' )), array( 'ID', 'post_title' ) ); piklist('field', array( 'field' => 'event_page', 'type' => 'select', 'scope' => 'post_meta', 'label' => 'Event Page (stored in post_meta)', 'description' => 'If there is a special page for this event, select it here.', 'choices' => $choices, )); piklist('field', array( 'field' => 'post_parent', 'type' => 'select', 'scope' => 'post', 'label' => 'Event Page (stored in post_parent)', 'description' => 'If there is a special page for this event, select it here.', 'choices' => $choices, ));Not surprisingly, behavior is the same for radio buttons.
HTH,
Donna -
June 2, 2016 at 11:29 pm #6572
mcmasterMemberp.s. Should have mentioned that I’m using Piklist 0.9.9.8
-
June 3, 2016 at 10:05 am #6573
SteveKeymasterWhat happens when you try to save “0”?
-
June 3, 2016 at 7:34 pm #6580
mcmasterMemberThere’s no error message, but the value remains whatever it was before. I can change it to another non-zero value but not zero.
I have the error isolated on a test site; would you like access to it?
-
June 3, 2016 at 7:38 pm #6581
mcmasterMember -
June 3, 2016 at 10:44 pm #6582
-
June 3, 2016 at 11:06 pm #6585
mcmasterMemberGreat, thanks!
-
-
AuthorPosts
- You must be logged in to reply to this topic.