Wordpress get_post_meta function.php

时间:2014-09-15 10:40:15

标签: wordpress

function getcity(){
    global $wpdb;
    global $post; 
    if($_POST['state'])
    {
        $id=$_POST['state'];

        $district = get_post_meta($post->ID , district, true);
        var_dump($district);
        $result=$wpdb->get_results("SELECT * FROM districts WHERE state_id='$id'");

        foreach($result as $row) {
            $city_name   = $row->district_name;
            $city_id     = $row->district_id;
            // echo '<option value="'.$city_id.'">'.$city_name.'</option>';
            ?>
            <option value="<?php echo $city_id; ?>" <?php if($district == $city_id){ echo
                'selected="selected"';} ?>><?php echo $city_name; ?></option>
            <?php

        }
    }
}
add_action("wp_ajax_nopriv_getcity", "getcity");
add_action("wp_ajax_getcity", "getcity");

这是我在function.php文件中的函数,我想获取当前帖子的post_id,我想在下拉列表中显示所选值。

0 个答案:

没有答案