2

The theme I purchased came without custom fields in the post/product editor. It uses a custom post type in its own admin php file. I've managed to add custom fields by pulling the following code out of wordpress core metabox.php file however I'm unsure how to get it to work. Its missing the area where the custom field values should go.

<div id="postcustomstuff">
<div id="ajax-response"></div>
<?php
$metadata = has_meta($post->ID);
list_meta($metadata);
meta_form(); ?>
</div>

2 Answers 2

8

The developer forgot to support "custom-fields" when calling register_post_type.

When editing a post, if there is no checkbox under screen options for Custom Fields that's why. In the init hook for my plugin I do...

register_post_type('mynamespace_product',
    array('labels' => array(
            'name' => __( 'Products' ),
            'singular_name' => __( 'Product' )
            ),
        'taxonomies' => array('category', 'product_type'), // this is IMPORTANT,                
        'public' => true,
        'has_archive' => true,
        'supports' => array('title','editor','custom-fields','comments')    
        )           
    );
Sign up to request clarification or add additional context in comments.

Comments

2

To get the custom fields associated to a post, you can query it this way:

 if ( get_post_meta($post->ID, 'my_customfield', true) ) : 
 echo get_post_meta($post->ID, 'my_customfield', true) 
 endif; 

Hope this helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.