Php wp_reset_postdata终止变量数据

Php wp_reset_postdata终止变量数据,php,wordpress,Php,Wordpress,我已经在Wordpress中为自定义帖子类型创建了一个归档页面。如果某些字段匹配,我想输出数据 在第一个if语句中,我想检查用户注册的产品(保存在$product中),并将其与当前项目自定义字段(保存在$title中)匹配 它所做的只是查看用户注册的内容,然后输出内容(即下面的所有数据) 我遇到的问题是wp\u reset\u postdata()正在删除$match中保存的数据。是否有办法解决此问题?如果我不包括post数据的设置,也不包括重置,那么页面的其余部分就不会显示正确的信息 我正在使

我已经在Wordpress中为自定义帖子类型创建了一个归档页面。如果某些字段匹配,我想输出数据

在第一个if语句中,我想检查用户注册的产品(保存在
$product
中),并将其与当前项目自定义字段(保存在
$title
中)匹配

它所做的只是查看用户注册的内容,然后输出内容(即下面的所有数据)

我遇到的问题是
wp\u reset\u postdata()
正在删除
$match
中保存的数据。是否有办法解决此问题?如果我不包括post数据的设置,也不包括重置,那么页面的其余部分就不会显示正确的信息

我正在使用高级自定义字段关系字段()

任何帮助都将不胜感激

User signed up as: <?php $current_user = wp_get_current_user();
$board = $current_user->work;
$product = $current_user->product;
echo $product; ?>
<br />

<?php while (have_posts()) : the_post(); ?>

<?php $products = get_field('product'); 
if( $products ):
    foreach( $products as $post): // variable must be called $post (IMPORTANT)
        setup_postdata($post);          
        $title = $post->post_title;
        echo $title;
        if($product == $title) {
            $match = "yes";
        }
    endforeach;
    wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif; ?>   

<?php if($match == "yes"){ ?>
<div id="module-area" style="margin-top:0px!IMPORTANT;">
    <div id="modules-top"></div>
    <div id="modules-repeat" style="position:relative;padding-left:10px;padding-right:10px;width:625px!IMPORTANT;">
        <div class="topic">
            <p><?php the_title(); ?></p>
        </div>
        <div class="description">
            <p><?php the_field('description') ?></p>
        </div>
        <div class="date">
            <p style="text-align:center!IMPORTANT;"><?php the_modified_time('d.m.y'); ?></p>
        </div>
        <div class="action">
            <a class="train-button" href="<?php echo the_permalink(); ?>"></a>                      
        </div>
        <div class="clear"></div>
    </div>
    <div style="margin-bottom:5px;" id="modules-bottom"></div>              
</div>  
<?php } ?>

<?php endwhile; ?>
用户注册为:

用户注册为:

wp_reset_postdata();
你只想显示$product=$title的帖子吗?还是想显示所有的帖子,除非设置了$products?@Damien如果$product=$title,那么是的。谢谢。我之前试过了——问题是它输出了标题(和其他数据)关系字段项的名称,而不是实际的自定义帖子本身。更新的答案..也许可以尝试一下?(抱歉输入错误)嗯,每个模块的标题都不同,但描述、时间和链接都是列表中第一项的名称。有趣。我添加了wp_reset_postdata();说明。这有帮助吗?抱歉-在没有实际看到部署的情况下很难进行此操作:)这更好。虽然匹配似乎不起作用,但它显示所有帖子,无论它们是否匹配。可能我没有正确完成匹配部分???
User signed up as: <?php $current_user = wp_get_current_user();
$board = $current_user->work;
$product = $current_user->product;
?>
<?php $products = get_field('product'); 
if( $products ):
    foreach( $products as $post): // variable must be called $post (IMPORTANT)
        setup_postdata($post);          
        $title = $post->post_title;
        if($product == $title) { 
                       wp_reset_postdata(); ?>
        <div id="module-area" style="margin-top:0px!IMPORTANT;">
            <div id="modules-top"></div>
            <div id="modules-repeat" style="position:relative;padding-left:10px;padding-right:10px;width:625px!IMPORTANT;">
                <div class="topic">
                    <p><?php the_title(); ?></p>
                </div>
                <div class="description">
                    <p><?php the_field('description') ?></p>
                </div>
                <div class="date">
                    <p style="text-align:center!IMPORTANT;"><?php the_modified_time('d.m.y'); ?></p>
                </div>
                <div class="action">
                    <a class="train-button" href="<?php echo the_permalink(); ?>"></a>                      
                </div>
                <div class="clear"></div>
            </div>
            <div style="margin-bottom:5px;" id="modules-bottom"></div>              
        </div>  
<?php           
        }
    endforeach;
endif; ?>   
wp_reset_postdata();