• I registered a post type called issue and added some meta fields. One of them is the meta_box sticky.

    function sticky	(){
      global $post;
      $custom = get_post_custom($post->ID);
      $sticky = $custom["sticky"][0];
      ?>
      <input type="checkbox" id="sticky" name="sticky" value="yes" <?php echo ($sticky == 'yes') ? 'checked="checked"':''; ?>/> <label for="sticky">Check to stick to the frontpage.</label><br />
      <?php } ?>

    Well this helps me to get all sticky marked posts and custom posts for a featured slider. The loop:

    $wpcust = new WP_Query(
    		array(
                'post_type' => array(
                    'post',
                    'issue',
                ),
    			'meta_key'=>'sticky',
    			'meta_value'=> 'yes',
    			'post_status' => 'publish',
                'showposts' => '2' )
            );
            if ( $wpcust->have_posts() ):
                while( $wpcust->have_posts() ) : $wpcust->the_post();

    When I mark a (normal) post sticky it will add all the custom fields for the custom post_type to that post and a I cannot delete them anymore.

    Any suggestions?

    The whole meta boxing:

    add_action("admin_init", "admin_init");
    
    function admin_init(){
      add_meta_box("issue_download", "Download Link", "issue_download", "issues", "side", "low");
      add_meta_box("issue_cover", "Cover Thumb", "issue_cover", "issues", "side", "low");
      add_meta_box("issue_highlight", "Highlight Issue", "issue_highlight", "issues", "side", "low");
      add_meta_box("sticky", "Sticky", "sticky", "issues", "side", "low");
      add_meta_box("issue_meta", "Credits", "issue_meta", "issues", "normal", "low");
      add_meta_box("sticky", "Sticky", "sticky", "videos", "side", "low");
    
    }
    
    function issue_download(){
      global $post;
      $custom = get_post_custom($post->ID);
      $issue_download = $custom["issue_download"][0];
      ?>
      <label>URL:</label>
      <input name="issue_download" value="<?php echo $issue_download; ?>" />
      <?php
    }
    
    function issue_cover(){
      global $post;
      $custom = get_post_custom($post->ID);
      $issue_cover = $custom["issue_cover"][0];
      ?>
      <label>URL:</label>
      <input name="issue_cover" value="<?php echo $issue_cover; ?>" /><br />
      <p>Needs to be 320x417px</p>
      <?php
    }
    
    function sticky	(){
      global $post;
      $custom = get_post_custom($post->ID);
      $sticky = $custom["sticky"][0];
      ?>
      <input type="checkbox" id="sticky" name="sticky" value="yes" <?php echo ($sticky == 'yes') ? 'checked="checked"':''; ?>/> <label for="sticky">Check to stick to the frontpage.</label><br />
      <?php
    }
    
    function issue_highlight (){
      global $post;
      $custom = get_post_custom($post->ID);
      $issue_highlight = $custom["issue_highlight"][0];
      ?>
      <input type="checkbox" id="issue_highlight" name="issue_highlight" value="highlight" <?php echo ($issue_highlight == 'highlight') ? 'checked="checked"':''; ?>/> <label for="issue_highlight">Check to make cover alpha 100%</label><br />
      <?php
    }
    
    function issue_meta() {
      global $post;
      $custom = get_post_custom($post->ID);
      $issue_meta = $custom["issue_meta"][0];
      ?>
      <p><textarea cols="50" rows="15" name="issue_meta"><?php echo $issue_meta; ?></textarea><br />
      This content is shown on the right side and could include the table of content, credits or other meta information of the issue.</p>
      <?php
    }
    
    add_action('save_post', 'save_details');
    
    function save_details(){
      global $post;
    
      update_post_meta($post->ID, "issue_download", $_POST["issue_download"]);
      update_post_meta($post->ID, "issue_cover", $_POST["issue_cover"]);
      update_post_meta($post->ID, "sticky", $_POST["sticky"]);
      update_post_meta($post->ID, "issue_highlight", $_POST["issue_highlight"]);
      update_post_meta($post->ID, "issue_meta", $_POST["issue_meta"]);
    }
  • The topic ‘Custom post_type with meta_key sticky conflict’ is closed to new replies.