• Once again I’m stuck, and it’s driving me mad!

    I’ve got custom post types set up, and also have custom fields.

    What I want to do is at my custom fields to the bottom of my ‘custom post’ page, in this case individual job vacancies

    I’ve tried this:

    <?php echo get_post_meta($post->ID, "Location", true); ?>
    <?php echo get_post_meta($post->ID, "Salary", true); ?>
    <?php echo get_post_meta($post->ID, "Job_Type", true); ?>

    Which doesn’t seem to work.

    Do I need to specify that it’s a post type=’Vacancy’ or something first?

    Thanks

Viewing 1 replies (of 1 total)
  • The get_post_meta is coded to only retrive post meta data, not custom types, if you want to fetch data on a custom post type you’ll need an alternate function i think.

    For ref.

    /**
     * Retrieve post meta field for a post.
     *
     * @since 1.5.0
     * @uses $wpdb
     * @link http://codex.wordpress.org/Function_Reference/get_post_meta
     *
     * @param int $post_id Post ID.
     * @param string $key The meta key to retrieve.
     * @param bool $single Whether to return a single value.
     * @return mixed Will be an array if $single is false. Will be value of meta data field if $single
     *  is true.
     */
    function get_post_meta($post_id, $key, $single = false) {
    	return get_metadata('post', $post_id, $key, $single);
    }

    That’s how the function currently looks.

    Use get_metadata as the function above does and see if that works (obviously changing post to your custom type).

Viewing 1 replies (of 1 total)

The topic ‘Showing custom fields on post page’ is closed to new replies.