Why cant i see my custom field ?.
-
My Custom Post Taxonomy Code
<?php /* Special Offer Post */ add_action('init', 'special_offers'); function special_offers() { $labels = array( 'name' => _x('special offers', 'post type general name'), 'singular_name' => _x('special_offer', 'post type singular name'), 'add_new' => _x('Add New', 'special offers'), 'add_new_item' => __('Add New special offers'), 'edit_item' => __('Edit special offers'), 'new_item' => __('New special offers'), 'view_item' => __('View special offers'), 'search_items' => __('Search special offers'), 'not_found' => __('No special_offerss found'), 'not_found_in_trash' => __('No special offerss found in Trash'), 'parent_item_colon' => '' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => true, 'menu_position' => 6, '_builtin' => false, 'menu_icon' => get_bloginfo('template_directory') . '/images/special-offer-icon.png', // Icon Path 'supports' => array('title','editor','thumbnail','cats' , 'brands') ); register_post_type('special_offers',$args); } register_taxonomy( 'brands', 'special_offers', array( 'hierarchical' => true, 'label' => __('Brands'), 'query_var' => 'brands' ) ); add_action( 'admin_init', 'my_admin3' ); function my_admin3() { add_meta_box( 'special_offer_meta_box', 'special offer Details', 'display_special_offer_meta_box', 'special_offer', 'normal', 'high' ); } ?> <?php function display_special_offer_meta_box( $special_offer ) { $post_description = esc_html( get_post_meta( $special_offer->ID, 'post_description', true ) ); $post_description2 = esc_html( get_post_meta( $special_offer->ID, 'post_description2', true ) ); ?> <table> <tr> <td style="width: 100%">Post Description[For Home Page]</td> <td><input type="text" size="80" name="special_offer_post_description" value="<?php echo $post_description; ?>" /></td> </tr> <tr> <td style="width: 100%">Post Description 2[For Home Page]</td> <td><input type="text" size="80" name="special_offer_post_description2" value="<?php echo $post_description2; ?>" /></td> </tr> </table> <?php } ?> <?php add_action( 'save_post', 'add_special_offer_fields', 10, 2 ); function add_special_offer_fields( $special_offer_id, $special_offer ) { if ( $special_offer->post_type == 'special_offers' ) { if ( isset( $_POST['special_offer_post_description'] ) && $_POST['special_offer_post_description'] != '' ) { update_post_meta( $special_offer_id, 'post_description', $_POST['special_offer_post_description'] ); } if ( isset( $_POST['special_offer_post_description2'] ) && $_POST['special_offer_post_description2'] != '' ) { update_post_meta( $special_offer_id, 'post_description2', $_POST['special_offer_post_description2'] ); } } }
Custom fields not showing in my editor
<div class="offer-post"> <?php $myquery['tax_query'] = array( 'relation' => 'OR', array( 'taxonomy' => 'brands', 'terms' => array('ALL'), 'field' => 'slug', ), array( 'taxonomy' => 'media', 'terms' => array('news', 'events'), 'field' => 'slug', ), ); query_posts($myquery); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="so-post-hom"> <h2 class="post-title"><?php the_title();?></h2><br /> <h3 class="post-desc"></h3> <div class="post-bar"> <a href="">Go!</a> </div> </div> <?php endwhile; else: ?> <?php endif; ?>
and this code working, but in another custom post
<?php echo esc_html( get_post_meta( get_the_ID(), 'employed_since', true ) ); ?>
please help me to correct the code.
i need to show the custom field(post_description)inside <h3 class=”post-desc”></h3>
and why can’t i see the custom field in editor ?
also if one field, what changes in the code ?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Why cant i see my custom field ?.’ is closed to new replies.