Custom Fields not showing up for custom post type

I'm a little new to WordPress development and am SO frustrated-- I created some custom post types, and am trying to add custom fields to them. For some reason, the fields will just not show up when I try to add a new post!!! Here is my code--this is in the custom post type file.

<?php /**  * Plugin Name: Art Beat  * Plugin URI: #  * Version: 1.0  * Author: bjorkland  * Author URI: http://localhost:8888/wp-admin/plugins.php?plugin_status=all&paged=1&s  * Description: A custom post type  * License: GPL2  */  class ArtBeat {  function __construct() {   add_action( 'init', array( $this, 'register_custom_post_type' ) ); } function register_custom_post_type() { register_post_type( 'artbeat', array(     'labels' => array(         'name'               => _x( 'Art Beats', 'post type general name', 'artbeat' ),         'singular_name'      => _x( 'Art Beat', 'post type singular name', 'artbeat' ),         'menu_name'          => _x( 'Art Beat', 'admin menu', 'artbeat' ),         'name_admin_bar'     => _x( 'Art Beat', 'add new on admin bar', 'artbeat' ),         'add_new'            => _x( 'Add New Art Beat', 'art', 'artbeat' ),         'add_new_item'       => __( 'Add New Art Beat', 'artbeat' ),         'new_item'           => __( 'New Art Beat', 'artbeat' ),         'edit_item'          => __( 'Edit Art Beat', 'artbeat' ),         'view_item'          => __( 'View Art Beat', 'artbeat' ),         'all_items'          => __( 'All Art Beats', 'artbeat' ),         'search_items'       => __( 'Search Art Beats', 'artbeat' ),         'parent_item_colon'  => __( 'Parent Art Beat:', 'artbeat' ),         'not_found'          => __( 'No Art Beat found.', 'artbeat' ),         'not_found_in_trash' => __( 'No Art Beat found in Trash.', 'artbeat' ),     ),      // Frontend     'has_archive'        => false,     'public'             => false,     'publicly_queryable' => false,      // Admin     'capability_type' => 'post',     'menu_icon'     => 'dashicons-businessman',     'menu_position' => 10,     'query_var'     => true,     'show_in_menu'  => true,     'show_ui'       => true,     'supports'      => array(         'title',         'author',         'comments',     ), ) ); } }  $ArtBeat = new ArtBeat;   function add_artbeat_meta_boxes() {  add_meta_box("artbeat_contact_meta", "Contact Details", "add_contact_details_artbeat_meta_box", "artbeats", "normal", "low"); }    function add_contact_details_artbeat_meta_box()   { global $post; $custom = get_post_custom( $post->ID );  ?>  <style>.width99 {width:99%;}</style>  <p> <label>Date:</label><br />   <textarea rows="5" name="date" class="width99"><?= @$custom["date"][0] ?></textarea>    </p>    <p>      <label>Museum:</label><br />      <input type="text" name="museum" value="<?= @$custom["museum"][0] ?>"    class="width99" />   </p>   <?php }  function save_artbeat_custom_fields(){  global $post;  if ( $post ) {   update_post_meta($post->ID, "date", @$_POST["date"]);   update_post_meta($post->ID, "museum", @$_POST["museum"]); } } add_action( 'admin_init', 'add_artbeat_meta_boxes' ); add_action( 'save_post', 'save_artbeat_custom_fields' ); 


If you have created an Class in your plugin then you should use the action hook for admin_init in class only just like you have used "init"

function __construct() {
  add_action( 'init', array( $this, 'register_custom_post_type' ) );
  add_action( 'admin_init', array( $this, 'add_artbeat_meta_boxes' ) );
  add_action( 'save_post', array( $this, 'save_artbeat_custom_fields' ) );

Hope this will help you out.

Category: custom post types Time: 2016-07-30 Views: 0

Related post

  • Strange issue with custom fields not showing data for certain posts but working fine on others 2016-02-06

    I have a very strange issue with custom fields on my site. I am using the custom fields for custom post types. So lets say the custom post type is called "cars". I will have various custom fields like "make", "model", "c

  • How to create Custom Taxonomy Search Drop Down for specific Post Type 2011-07-19

    I have a number of custom post types which share a custom taxonomy. I'm trying to implement a dropdown search box using php (to insert into a widget or elsewhere) that allows selection of a taxonomy term, and returns the posts which have that term, b

  • Woocommerce custom fields not showing for role [on hold] 2016-06-12

    If I add a user via the Shop Manager role (created by WooCommerce), none of the Woocommerce custom fields show (which show when logged in as administrator), ie: Address Phone Number etc... I have enabled all capabilities via the Role Editor plugin, b

  • Custom fields not showing on front-end after xml import 2013-11-06

    I've just imported 700+ custom posts from one WP install to another using the XML import/export option. Everything seems to be imported fine: the field values are showing in the DB and on the admin side. However, if I try to get the field value on th

  • custom fields not showing before get_header 2015-06-21

    I am trying to use this code in my WordPress site <?php if(get_post_format() == 'video'){ function insert_game(){ get_template_part( 'content', 'video-top' ); } add_action( 'colormag_after_header', 'insert_game' ); } ?> <?php get_header(); ?>

  • Custom Fields Not Showing 2013-01-23

    I have this custom field for a post: key: price value: 2000 I've added this to my loop: <div class="buyitnow"><?php $price = get_post_meta($post->ID, 'price', true); if ( $price ) { ?> Price: $<?php echo number_format($price ,&

  • Custom field not showing 2013-08-08

    I am trying to get 3 images and their links which I have defined as custom fields. The custom field aren't displayed and when I var_dump() my get_post_meta() it returns string(0)"", what am i doing wrong? <div class="latest"> <

  • Custom field not showing in page layout 2015-06-11

    I have successfully created a custom field with MetaData API but it it's not visible in lead page. below is the code how I create it. public bool CreateCustomField_LongTextArea(SforceService binding) { bool Response = true; try { CustomField cf = new

  • featured image metabox not showing on the default post types edit page 2014-12-19

    I can't get the Featured Image metabox to show up on the edit page for the default post and page post types. Though as opposed to this question, it does work for the custom post type I've created using a plugin. It just doesn't work with the default

  • Custom field not showing on edit form 2013-04-09

    I'm fairly new to drupal development and still trying to wrap my brain around the API. I run an athletic based website and need to be able to store race times using a mm:ss.00 format. I haven't seen any contributed modules that can do this, so I deci

  • Blog listing not showing dates for every post and arrow missing off image 2016-01-14

    I am trying to get the blog to appear the same as in the first post but for some reason the date disappears and so does the arrow on top of the image. You can view my site here. The current code: <style> #title_wrapper { width: 488px; } h2 { font-si

  • EE3.0 - custom member field not showing up in registration form in CP 2015-10-26

    I have created a custom member field in the CP and set it to "required", "show in registration" and "show in profile". However, it doesn't show up in the form when I register a new member in the CP and it doesn't show up in t

  • Add different custom markers for different post types in Google maps API 2015-09-17

    I'm using the Google maps javascript API to create a map showing locations for multiple post types. I can create a custom map marker icon, but cannot figure out how to display a different marker icon for each of the different post types. What I have

  • Prevent post from being published if custom fields not filled 2012-02-11

    I have a custom post type Event that contains a starting and ending date/times custom fields (as metaboxes in the post edit screen). I would like to make sure that an Event cannot get published (or scheduled) without the dates being filled, as that w

  • How do I create custom fields for multiple post types? 2011-12-15

    I have created multiple post types and now want to create multiple custom fields for each post type. I am not entirely how to but more specifically I believe I am doing something wrong when trying to save the meta field data. I've based my project fo

  • Users with custom roles not showing in post author select box 2013-03-21

    I am using a function to create new user roles and delete some defaults. However, they are not showing up in the post author box! Only the admin shows up because they are selected as an admin. Any user with a custom role does not show up. Any idea wh

  • custom object fields not showing up after deployment 2013-04-30

    I created a changeset and deployed around 40 custom objects to another sandbox. On the destination sandbox, the custom fields dont show up on the page layout when i edit or add a new record for the custom object. I know it is a permission issue and i

  • term/tag not being saved for custom post type 2013-12-06

    I have been using a chunk of code as a plugin that was suggested in the answer to this question. Please check the code provided below instead of the one in the question, as I may have modified it a bit. The plugin works fine for the normal post type

  • Custom post type taxonomoy template is not showing more than two post 2016-06-24

    I am trying to make a page on a custom post type(new_arrivals) taxonomies (sieraden, trouwringen, horloges) template. I have made the template taxonomy-new_arrivalstype.php like this. Inside I add the while loop for post geeting. But the loop is not

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 1.793 (s). 13 q(s)