Php 使用get#u字段(';status';)的DB查询中的字段返回NULL

Php 使用get#u字段(';status';)的DB查询中的字段返回NULL,php,arrays,wordpress,null,Php,Arrays,Wordpress,Null,当我试图在页面上显示'status'字段时,我得到了NULL。当我执行var\u dump时,它也会显示NULL。不知道怎么了 我试图在图像覆盖类中显示文本 其他所有风险值均显示为无问题 我试过status==和status=等,但似乎没有任何效果,我肯定错过了什么 <?php unset($bed); unset($type); unset($salerent); unset($pricemin); unset($pricemax); unset($status); $s

当我试图在页面上显示
'status'
字段时,我得到了
NULL
。当我执行
var\u dump
时,它也会显示NULL。不知道怎么了

我试图在图像覆盖类中显示文本

其他所有风险值均显示为无问题

我试过status==和status=等,但似乎没有任何效果,我肯定错过了什么

<?php
    unset($bed); unset($type); unset($salerent); unset($pricemin); unset($pricemax); unset($status);
    $salerent = 'sale';
    $salerent2 = 'rent';
    $type = 'villa'; $type2='condo'; $type3='house'; $type4='land';
    $status = 'NEW'; $status2='SOLD'; $status3='HOT DEAL';
    $bed = 'all';
    $minprice='0';
    $maxprice='999999999';
    if ($bed=='all') 
    {
        $bed1=1;$bed2=2;$bed3=3;$bed4=4;$bed5=5;
        $bed6=6;$bed7=7;$bed8=8;$bed9=9;$bed10=10;
    }
    if ($salerent=='rent'){
        $p0text="Price (per month)";
        $p1text="0 - 10,000";
        $p2text="10,000 - 25,000";
        $p3text="25,000 - 40,000";
        $p4text="40,000 - 80,000";
        $p5text="80,000+";  
    }
    else{
        $p0text="Price";
        $p1text="0 - 3 mill";
        $p2text="3 - 6 mill";
        $p3text="6 - 10 mill";
        $p4text="10 - 20 mill";
        $p5text="20+ mill"; 
    }
?>
<?php wp_head(); ?>
</head>
<body>
<?php include( get_template_directory() . '/menu.php'); ?>  
    <!-- Main-->
    <main>
    <!-- Main Container-->
    <div class='container '>
        <div class="row" style="vertical-align:bottom;">
            <div class="col-lg-12 col-md-12 text-center">
                <h1 class="hometitle"><span style="font-size:1.1em; color:red; position:absolute; margin-left:-4px; margin-top:-19px;  transform: rotate(25deg);">/</span>star property<br /><span class="mainsub"> Villas, Condos &amp; Houses for Sale &amp; Rent in Hua Hin</span></h1>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12 col-md-12 center-on-small-only text-center">
                <div class="row searchbox">
                    <div class="col-lg-12">
                        <form id="searchurl" method="POST" action="http:// .com/search-result/?">
                            <span class="filter">Search:</span>
                            <select class="custom-select mysearch" id="salerent" name="salerent">
                                <option value="sale" <?php if($salerent=='sale'){echo "selected";}?>>Sale</option>
                                <option value="rent" <?php if($salerent=='rent'){echo "selected";}?>>Rent</option>
                            </select>

                            <select class="custom-select mysearch" id="type" name="type">
                                <option value="villa" <?php if ($type=='villa'){echo "selected";}?>>Villa</option>
                                <option value="condo" <?php if ($type=='condo'){echo "selected";}?>>Condo</option>
                                <option value="house"<?php if ($type=='house'){echo "selected";}?>>House</option>
                                <option value="house"<?php if ($type=='land'){echo "selected";}?>>Land</option>
                                <option value="house"<?php if ($type=='commercial'){echo "selected";}?>>Commercial</option>
                            </select>

                            <select class="custom-select mysearch" id="bed" name="bed">
                                <option value="all">Bedrooms</option>
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                            </select>

                            <select class="custom-select mysearch" id="pricerange" name="pricerange">
                                <option id="p0" value="all"><?php echo $p0text;?></option>
                                <option id="p1" value="1"><?php echo $p1text;?></option>
                                <option id="p2" value="2"><?php echo $p2text;?></option>
                                <option id="p3" value="3"><?php echo $p3text;?></option>
                                <option id="p4" value="4"><?php echo $p4text;?></option>
                                <option id="p5" value="5"><?php echo $p5text;?></option>
                            </select>
                            <input class="col-lg-1 col-md-1 mysearch" type="text" id="searchid" name="searchid" placeholder="#ID/Project" />
                            <button type="submit" onclick="document.getElementById('searchurl').submit();" id="submitbutton" class="btn btn-primary btn-md">SEARCH</button>
                        </form>
                    </div>
                </div>
            </div>  
       </div>



       <div class="row zero col-lg-12 col-md-12 text-center">
           <h2 style="width:100%; margin:0.8em 0 0.8em 0;">New Listings:<br /><span class="sub"> Properties for Sale &amp; Rent in Hua Hin</span></h2>
       </div>  
       <div class="row" style="padding:0; margin:0;">

           <?php
               $args = array(
                   'posts_per_page'    => 6,
                   'post__in' => array(22094, 16782, 20898, 19838, 22150, 1442, 1794),
                   'post_type'     => 'post',
                   'no_paging' => true,
                   'order' => DESC,
                   'cat'           => 2,
               );
               // query
               $the_query = new Wp_Query( $args ); 
           ?>

           <ul id="starlistings" class="col-lg-12 col-md-12 row" >
               <?php if( $the_query->have_posts() ): ?>
                    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
                        <li class="col-lg-6 col-md-6" style="float:left; ">
                            <div class="col-lg-12 col-md-12 listingframe" >
                                <div class="row" style="background-color:#77c0ff" "padding-top: 20px; padding-bottom: 20px">
                                    <div class="text-center col-lg-12 col-md-12">
                                        <a class="listingslink" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                    </div>
                                </div>
                                <div class="row" style="padding-top:0.8em;">
                                    <div class="text-center col-lg-12 col-md-12" class="zero">
                                        <a href="<?php the_permalink(); ?>"><img src="<?php the_field('image_1'); ?>" class="w-100" alt="<?php the_field('image_1_alt'); ?>" title="<?php the_field('area_project'); ?> <?php $type = get_field('type'); if ($type=='Villa') echo 'House'; else { the_field('type');} ?> for <?php the_field('sale_or_rent'); ?> in Hua Hin">**<div class="image-overlay"><?php $status = get_field('status'); if ($status=='NEW') echo 'NEW ARRIVAL'; else { the_field('status');} ?></div>**</a>

                                    </div>

                                </div>
                            </div>
                            <div class="text-center listingsdivider col-lg-12 col-md-12">
                                <span>
                                    <span class="listingsicons" style="padding:5px 0.5em 5px 0;">ID #<?php the_field('property_id'); ?></span>
    <span class="listingsicons" style="padding:5px 0.5em 5px 0;"><?php $price = get_field('Price'); echo number_format($price, 0, '', ','); ?> baht<?php $saleorrent = get_field('sale_or_rent'); if($saleorrent=='Rent'){echo ' ';} ?> 
                                    </span>
                                    <span class="listingsicons"  style="padding:5px 0.5em 5px 0.5em;"><img src="/wp-content/themes/startheme/images/house.png" alt="house" style="height:12px; width:auto; margin:-4px 8px 0 0; padding:0; opacity:0.7" /><?php the_field('living_space'); ?> SQM</span>
                                    <span class="listingsicons" style="padding:5px 0.5em 5px 0.5em;"><img src="/wp-content/themes/startheme/images/beds.png" alt="bedrooms" style="height:12px; width:auto; margin:-2px 4px 0 -3px; padding:0; opacity:0.6" /><?php the_field('bedrooms'); ?> Beds</span>
                                    <span style="padding:5px 0 5px 0.5em; "><img src="/wp-content/themes/startheme/images/bathrooms.png" alt="bathrooms" style="height:15px; width:auto; margin:-2px 6px 0 2px; padding:0; opacity:0.6;" /><?php the_field('bathrooms'); ?> Baths</span>
                                </span>

                                <div style="background-color: white; padding-top: 10px; padding-bottom: 5px"><span><?php $excerpt = wp_trim_words( get_field('property_description' ), $num_words = 10, $more = '<a href="'.get_permalink().'">... more</a>' ); echo $excerpt; ?></span></div>
                            </div>
                        </li>
                    <?php endwhile; ?>
                <?php endif; ?>
            </ul>
       </div>

/星级酒店别墅、公寓和公寓;待售房屋及;华欣的租金
搜索:
>租
>公寓
>土地
搜寻
新上市:
待售物业&;华欣的租金
  • 身份证# 泰铢 平方米 床 洗澡

好的,我已经解决了这个问题

我希望这能帮助任何有同样问题的人

将wp admin中的字段添加到“高级自定义字段”字段组时

确保将“返回值”更改为值

Label和/Array不适用于get\u字段或\u字段


希望这对其他人有所帮助。

您是否尝试将post id作为第二个参数显式传递?(如果($status='NEW')肯定是错误的,那是一个赋值,而不是比较。)是的,我已经传递了post id和listing id等,它们都有效。但是,只要我添加status=='NEW',它就会显示NULL,我认为代码是正确的,但是我希望得到比我聪明的人的任何建议。我甚至不知道你的意思。您在哪里“添加”状态==“新建”?请更新您的代码以显示您当前拥有的内容。“它们都能工作”-那么现在到底有什么和哪里不起作用?很难判断您的实际问题是什么。我已经更新了代码。问题出在image overlay类或status变量中,当我对status变量执行var_转储时,它会显示NULL,我不知道为什么。当所有其他变量显示数据库中的数据时,您试图将其转储到哪里…?执行
var_转储(get_字段('status')在循环中,它毫无疑问地验证此调用是否能够正确读取值。