如何使用cp_address_line在地图上显示新帖子?

时间:2012-08-17 06:49:33

标签: wordpress map

我已经从几个文本框更改了地址字段:cp_street,cp_city,cp_state,cp_country和cp_zip

进入

cp_address_line。

旧帖子正在地图上显示,但新帖子没有。请告诉我为什么这段代码错了:

    <?php
add_action('wp_ajax_query_geo_ads', 'query_geo_ads');
add_action('wp_ajax_nopriv_query_geo_ads', 'query_geo_ads');
add_action('wp_ajax_get_image_url', 'get_image_url');
add_action('wp_ajax_nopriv_get_image_url', 'get_image_url');

add_action('wp_ajax_query_total', 'query_total');
add_action('wp_ajax_nopriv_query_total', 'query_total');


if (defined('MULTISITE') && (MULTISITE))
{

    if (!defined('TT'))
        define('TT', plugins_url('/geo-ads/timthumb_wpmu.php'));
}
else
{
    if (!defined('TT'))
        define('TT', plugins_url('/geo-ads/timthumb.php'));
}

function query_total()
{
    global $wpdb;
    $table = $wpdb->prefix.'cp_ad_geocodes';

    $q = "SELECT COUNT(*) FROM $table t LEFT JOIN $wpdb->posts p ON (p.ID = t.post_id) WHERE p.post_status = 'publish'";
    $c = $wpdb->get_var($q);
    echo $c;

    die();

}

function query_geo_ads()
{   
    if ($_GET['range'] == 'true') {
        query_geo_ads_refresh();
    }
    else {
    global $wpdb;   
    $table = $wpdb->prefix.'cp_ad_geocodes';
    $querystr = "SELECT t.post_id, t.category, t.lat, t.lng, p.post_title, p.post_content, m.meta_value as price, CONCAT(wpo_su.option_value, REPLACE( REPLACE( REPLACE( REPLACE(wpo.option_value,'%year%',date_format(p.post_date,'%Y')) ,'%monthnum%',date_format(p.post_date,'%m')) ,'%day%',date_format(p.post_date,'%d')) ,'%postname%',p.post_name ) ) as permalink 
                FROM  $table t LEFT JOIN $wpdb->posts p ON (p.ID = t.post_id)
                INNER JOIN $wpdb->options wpo ON wpo.option_name='permalink_structure'
                INNER JOIN $wpdb->options wpo_su ON wpo_su.option_name='siteurl'
                LEFT JOIN $wpdb->postmeta m ON (m.meta_key = 'cp_price') AND (m.post_id = p.ID)
                WHERE p.post_status = 'publish' 
                    AND p.post_type = 'ad_listing' ";       

    $ads = $wpdb->get_results($querystr);   

    $expires = 50000;
    $cache_time = mktime();

    header("Cache-Control: max-age:" . $expires . ", must-revalidate"); 
    header("Expires: " . gmdate("D, d M Y H:i:s",$cache_time+$expires) . " GMT");

    echo json_encode($ads); 
    die();
    }
}

function get_image_url()
{   $post_id = intval($_POST['id']);
    $attachment = get_posts(array('post_type' => 'attachment','post_status' => 'publish','order' => 'ASC','orderby' => 'post_date','post_mime_type' => 'image','post_parent' => $post_id));
    $height = 100;
    $width = 100;
    $url = TT.'?src='.wp_get_attachment_url($attachment[0]->ID, false).'&h='.$height.'&w='.$width;                      
    if ($attachment)
        echo $url;
    die();
}

function query_geo_ads_refresh() {
?>
<div class="undertab"><span class="big">Classified Ads / <strong><span class="colour">Just Listed</span></strong></span></div>
<?php
    global $wpdb,$wp_query, $post;

    $exclude_categories = $_REQUEST['exclude_categories'];
    $term_id = $_REQUEST['term_id'];
    $term_slug = $_REQUEST['term_slug'];
    $taxonomy_name = $_REQUEST['taxonomy_name'];
    $northeast_lng = $_REQUEST['northeast_lng'];
    $northeast_lat = $_REQUEST['northeast_lat'];
    $southwest_lng = $_REQUEST['southwest_lng'];
    $southwest_lat = $_REQUEST['southwest_lat'];

    if(!empty($exclude_categories)) {
        $exclude_categories = explode(';', $exclude_categories);
    }
    if(!$term_id) // this means root
        //$term_categories = get_terms( 'ad_cat', 'orderby=count&hide_empty=0' );
        $term_categories = get_terms( 'ad_cat', 'order=DESC','orderby=post_date' );
    else {
        $current_term = get_term_by( 'slug', $term_slug, $taxonomy_name );
        $term_categories = get_terms( $taxonomy_name, 'order=DESC','orderby=post_date' );

        if(empty($term_categories))
            $term_categories[] = $current_term;
    }

    foreach ($term_categories as $catinfo_obj)
    {
        $term_id = $catinfo_obj->term_id;
        $arrsrch = array("'");
        $arrrep = array('');
        $name = htmlspecialchars_decode($catinfo_obj->name);
        $name = strtolower(str_replace($arrsrch,$arrrep,$name));
        if(!empty($exclude_categories)) {
            if(in_array(strtolower($name), $exclude_categories))
                continue;
        }
        $subterm_ids = get_term_children( $term_id, 'ad_cat' );
        $subterm_ids[] = $term_id;
        $term_ids = implode(',', $subterm_ids);

        if($term_id)
        {
            $my_post_type = "'ad_listing'";
            $sql = "select * from $wpdb->posts p where p.post_type in ($my_post_type) and p.post_status in ('publish') and p.ID in (select tr.object_id from $wpdb->term_relationships tr join $wpdb->term_taxonomy t on t.term_taxonomy_id=tr.term_taxonomy_id where t.term_id in ($term_ids) )";

            $postinfo = $wpdb->get_results($sql);

            $data_arr = array();
            $geo_codes = array();

            if($postinfo)
            {
                $srcharr = array("'");
                $replarr = array("\'");
                foreach($postinfo as $postinfo_obj)
                {
                    $ID = $postinfo_obj->ID;
                    $title = str_replace($srcharr,$replarr,($postinfo_obj->post_title));
                    $plink = get_permalink($postinfo_obj->ID);

                    $geocode = cp_get_geocode($ID);
                    $lat = $geocode['lat'];
                    $lng = $geocode['lng'];
                    // check current post geo place is within map coord area
                    if($lat > $northeast_lat || $lat < $southwest_lat)
                       continue;
                    if($northeast_lng > $southwest_lng) {
                        if($lng > $northeast_lng || $lng < $southwest_lng)
                            continue;
                    } else {
                        if($lng > 0 && $lng < $southwest_lng)
                            continue;
                        if($lng < 0 && $lng > $northeast_lng)
                            continue;
                    }
                    $address = get_post_meta($ID,'cp_address_line',true);
                    if(!empty($address))
                        $address = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_address_line',true)));
                    else {
                        $street = get_post_meta($ID,'cp_street',true);
                        $city = get_post_meta($ID,'cp_city',true);
                        $state = get_post_meta($ID,'cp_state',true);
                        $country = get_post_meta($ID,'cp_country',true);
                        if(!empty($street))
                            $address .= $street . ', ';
                        if(!empty($city))
                            $address .= $city . ', ';
                        if(!empty($state))
                            $address .= $state . ', ';
                        if(!empty($country))
                            $address .= $country . ', ';
                        $address = trim($address);
                        $address = substr($address, 0, strlen($address)-1);
                        $address = str_replace($srcharr,$replarr,$address);
                    }

                    $phone = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_phone',true)));
                    $email = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_email',true)));
                    $author = get_userdata($postinfo_obj->post_author);
            $category = get_the_category($postinfo_obj->ID);
                    if($postinfo_obj->post_type == 'ad_listing') {
                        $timing = date('M d, Y',strtotime(get_post_meta($ID,'cp_start_date',true))).' to '.date('M d, Y',strtotime(get_post_meta($ID,'cp_end_date',true)));
                    } else {
                        $timing = date('M d, Y',strtotime(get_post_meta($ID,'st_date',true))).' to '.date('M d, Y',strtotime(get_post_meta($ID,'end_date',true))).'<br />'.get_post_meta($ID,'st_time',true).' to '.get_post_meta($ID,'end_time',true);
                    }
                ?>
                    <?php appthemes_before_post(); ?>

        <div class="post-block-out">

            <div class="post-block">

                <div class="post-left">

                    <?php if ( get_option('cp_ad_images') == 'yes' ) cp_ad_loop_thumbnail($ID); ?>

                </div>
                <div class="<?php if ( get_option('cp_ad_images') == 'yes' ) echo 'post-right'; else echo 'post-right-no-img'; ?> <?php echo get_option('cp_ad_right_class'); ?>">

                <!--    <h3><a href="<?php echo $plink; ?>"><?php if ( mb_strlen( $title ) >= 75 ) echo mb_substr( $title, 0, 75 ).'...'; else echo $title; ?></a></h3>

                    <div class="clr"></div>

                    <p class="post-meta">
                    <span class="folder">
                    <a href="/ad-category/<?php echo $catinfo_obj->slug; ?>/">
                    <?php echo $name; ?>
                    </a>
                </span> | 
                <span class="owner">
                    <a href="/author/<?php echo $author->user_nicename; ?>">
                        <?php echo $author->display_name; ?>
                    </a>
                </span> |
                <span class="clock"><span><?php echo $timing; ?></span></span>
                </p>-->


                </div>

                <div class="clr"></div>

            </div><!-- /post-block -->

        </div><!-- /post-block-out -->
     <?php
                }
            }            
        }        
    }

    die();
}
?>

1 个答案:

答案 0 :(得分:0)

似乎在每个函数的最后调用die(),阻止它返回成功状态代码。

删除每个处理函数的最后die(),操作应该可以正常工作。