Wordpress 输出自定义帖子数据

Wordpress 输出自定义帖子数据,wordpress,output,custom-post-type,Wordpress,Output,Custom Post Type,我是WordPress的新手。简言之,我希望将自定义帖子输出到页面上,但多次尝试均未成功 我已经成功创建了一个自定义帖子类型,它通过自定义字段保存自定义数据 <?php /*------------------------------------------------------------------------ -> CREATE SECTION FOR LOCATION MANAGEMENT IN WORDPRESS ADMIN AREA

我是WordPress的新手。简言之,我希望将自定义帖子输出到页面上,但多次尝试均未成功

我已经成功创建了一个自定义帖子类型,它通过自定义字段保存自定义数据

<?php

    /*------------------------------------------------------------------------
        ->  CREATE SECTION FOR LOCATION MANAGEMENT IN WORDPRESS ADMIN AREA
    ------------------------------------------------------------------------*/

    add_action('init', 'location_manager_register');
    function location_manager_register() {
        $args = array(
            'label' => __('Locations'),
            'singular_label' => __('location'),
            'public' => true,
            'show_ui' => true,
            'capability_type' => 'post',
            'hierarchical' => true,
            'has_archive' => true,
            'supports' => array('title', 'thumbnail'),
            'rewrite' => array('slug' => 'locations', 'with_front'=> false)
        );
        register_post_type('locations', $args);

    }

    /*------------------------------------------------------------------------
        ->  ADD BOX WHICH WILL CONTAIN CUSTOM TEXT FIELDS TO NEW SECTION
    ------------------------------------------------------------------------*/

    // CREATE THE BOX
    add_action("admin_init", "contact_manager_add_meta");
    function contact_manager_add_meta() {
        add_meta_box(
            "location-meta",
            "Location Options",
            "location_manager_meta_options",
            "locations",    // THIS PLACES THE BOX IN THE RIGHT SECTION
            "normal",       // PLACEMENT WITHIN SECTION
            "high"          // PRIORITY OF BOX
        );
    }

    // CREATE CUSTOM VALUES & ADD TEXT BOXES WITH CUSTOM VALUES
    function location_manager_meta_options() {
        global $post;
        if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return $post_id;
        }
        $custom = get_post_custom($post->ID);
        $address = $custom["address"][0];
        $telephone = $custom["telephone"][0];
        $fax = $custom["fax"][0];
        $email = $custom["email"][0];
?>
        <style type="text/css">
            <?php include('css/contact_manager.css'); ?>
        </style>

        <div class="contact_manager_extras">
            <div>
                <label> Address: </label>
                <input type="text" name="address" value="<?php echo $address; ?>"/>
            </div>
            <div>
                <label> Telephone: </label>
                <input type="text" name="telephone" value="<?php echo $telephone; ?>"/>
            </div>
            <div>
                <label> Fax: </label>
                <input type="text" name="fax" value="<?php echo $fax; ?>"/>
            </div>
            <div>
                <label> Email: </label>
                <input type="text" name="email" value="<?php echo $email; ?>"/>
            </div>
        </div>
<?php
    } // END function location_manager_meta_options

    // ADD FUNCTIONALITY TO SAVE THE FIELD VALUES
    add_action("save_post", "contact_manager_save_extras");
    function contact_manager_save_extras() {
        global $post;
        if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return $post_id;
        }
        else {
            update_post_meta($post->ID, "store_name", $_POST["store_name"]);
            update_post_meta($post->ID, "address", $_POST["address"]);
            update_post_meta($post->ID, "telephone", $_POST["telephone"]);
            update_post_meta($post->ID, "fax", $_POST["fax"]);
            update_post_meta($post->ID, "email", $_POST["email"]);
        }
    }

?>

地址:
这有用吗

<?php

$args = array(
    'post_type' => 'locations',
    'some_thing_here' => '',
    'some_thing_here' => '',
    'some_thing_here' => '',
    'some_thing_here' => ''
);

$mylocations = new WP_Query( $args );

if ( $mylocations -> have_posts() ) : while ( $mylocations->have_posts() ) : $mylocations -> the_post();

?>

<?php the_title(); ?>    
<?php the_content(); ?>    

<?php endwhile; else: ?>

    Oops, there are no Locations.

<?php endif; ?>

哎呀,没有位置。

编辑

还有一个关于这个问题的讨论,还有一些额外的例子

请记住,我的php非常基本,但我认为您可以通过执行以下操作将元日期放在$中

<?php 
    $adress = get_post_meta($post->ID, 'adres', true);
    $telephone = get_post_meta($post->ID, 'telephone', true);
    $fax = get_post_meta($post->ID, 'fax', true);
?>

然后呼应出来:

<?php echo $adress; ?>


希望这能有所帮助。

可能希望查看realy powerfull with meta Box等。谢谢,但我如何专门针对自定义字段,如地址和电子邮件等?比如在内容()下面?谢谢。这就是我需要的。明亮的
<?php echo $adress; ?>