[wp-trac] [WordPress Trac] #15995: query is separating post_type 'post' from custom post_types when retrieving custom field

WordPress Trac wp-trac at lists.automattic.com
Tue Dec 28 16:40:16 UTC 2010


#15995: query is separating post_type 'post' from custom post_types when retrieving
custom field
-------------------------------+------------------------------
 Reporter:  bowstreet          |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Post Types         |     Version:  3.0.3
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |
-------------------------------+------------------------------

Comment (by bowstreet):

 Thank you, I'm still checking back on this for hours now. The SQL query
 always brings the ordered result correctly but the query doesn't. I must
 admit that the query is giving the proper output when just using the
 register_post_type and adding a custom field in the backend with the name
 'sticky' and the value 'yes' but as soon as you add a meta_box for the
 meta_key sticky it will really make it 'sticky'. Means that you can see
 the little "Sticky" mark in the overview of the post_type. I don't know
 the difference between making a custom field with the name sticky or
 adding a meta_box with the name sticky. It looks like the tiny word
 'sticky' was making all the trouble.

 The code below should help reproducing the bug.

 {{{
 add_action('init', 'issue_custom_init');
 function issue_custom_init()
 {
   $args = array(
         'label' => __('Issues'),
     'public' => true,
     'publicly_queryable' => true,
     'show_ui' => true,
     'show_in_menu' => true,
     'query_var' => true,
     'rewrite' => true,
     'capability_type' => 'post',
     'has_archive' => true,
     'hierarchical' => true,
     'menu_position' => null,
     'supports' =>
 array('title','editor','thumbnail','excerpt','comments','revisions
 ','custom-fields')
   );
   register_post_type('issues',$args);
 }

 add_action("admin_init", "admin_init");

 function admin_init(){
   add_meta_box("sticky", "Sticky", "sticky", "issues", "side", "low");
 }

 function sticky(){
   global $post;
   $sticky = get_post_meta($post->ID, 'sticky', true);

   echo '<input type="checkbox" id="sticky" name="sticky" value="yes"';
   echo ($sticky == 'yes') ? 'checked="checked"':'' .'/> ';
   echo '<label for="sticky">Check to stick to the frontpage.</label>';
 }

 add_action("save_post", "save_details");

 function save_details($post_id) {
      global $post;

      if(isset($_POST['post_type']) && ($_POST['post_type'] == "issues")) {
                 update_post_meta($post->ID, "sticky", $_POST["sticky"]);
      }
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15995#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list