Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带查询的Wordpress PHP回显结果_Php_Wordpress_Loops_If Statement - Fatal编程技术网

带查询的Wordpress PHP回显结果

带查询的Wordpress PHP回显结果,php,wordpress,loops,if-statement,Php,Wordpress,Loops,If Statement,我在页面上有一个结果列表(每个结果都是自定义帖子类型的标题)。每个自定义帖子都附加了元数据(存储在数据库中的wp_Posteta中),其中一位元数据是变量widding_hidden_is_completed 对于此变量设置为0的每个自定义帖子,我希望回显一条错误消息 例如,假设我有ID为1,2,3,4的帖子,并且只有帖子2和3的变量widding\u hidden\u设置为1,那么我需要回显两条单独的错误消息:帖子1的错误消息和帖子4的错误消息(应该用单独的div包装) 以下是我到目前为止的情

我在页面上有一个结果列表(每个结果都是自定义帖子类型的标题)。每个自定义帖子都附加了元数据(存储在数据库中的wp_Posteta中),其中一位元数据是变量
widding_hidden_is_completed

对于此变量设置为0的每个自定义帖子,我希望回显一条错误消息

例如,假设我有ID为1,2,3,4的帖子,并且只有帖子2和3的变量
widding\u hidden\u设置为1,那么我需要回显两条单独的错误消息:帖子1的错误消息和帖子4的错误消息(应该用单独的div包装)

以下是我到目前为止的情况:

global $wpdb;
$args = array(
'post_type' => 'bookings',
'meta_query' => array(
    array(
        'key' => 'wedding_user',
        'value' => $current_user->display_name,
        'compare' => '=',
    )
)
);
// Errors query
$errors_query = new WP_Query( $args );
// The Loop
if ( $errors_query->have_posts() ) {
while ( $errors_query->have_posts() ) {
    $errors_query->the_post();

// Fill out form \
$is_form_complete = get_post_meta( $errors_query->post->ID, 'wedding_hidden_is_completed', true );

if($is_form_complete !=1) {
$error_message = '<p>Error with post'.$errors_query->post->ID.'</p>';
}

?>
<div class="errors"><?php echo $error_message; ?></div>
<?php
}
}
global$wpdb;
$args=数组(
“post_type”=>“bookings”,
“元查询”=>数组(
排列(
“密钥”=>“婚礼用户”,
'value'=>$current\u user->display\u name,
“比较”=>“=”,
)
)
);
//错误查询
$errors\u query=新的WP\u查询($args);
//环路
如果($errors\u query->have\u posts()){
而($errors\u query->have\u posts()){
$errors\u query->the\u post();
//填表\
$is\u form\u complete=get\u post\u meta($errors\u query->post->ID,'wedding\u hidden\u is\u completed',true);
如果($is_form_complete!=1){
$error_message='发布错误。$errors_query->post->ID.

; } ?> 试试这个

替换

if($is_form_complete !=1) {
$error_message = '<p>Error with post'.$errors_query->post->ID.'</p>';
}

?>
<div class="errors"><?php echo $error_message; ?></div>
<?php
然后在循环中(使用.=让我们添加到变量)

//表单不完整
如果($is_form_complete!=1){
$error\u message.='预订表单ID发行版。$errors\u query->post->ID.'需要完成。

'; } //到期存款 如果($已支付押金!=1){ $error\u message.='预订表单ID发行版。$errors\u query->post->ID.“存款现在到期。

”; } //到期全额付款 如果($is_full_amt_paid!=1){ $error\u message.='预订表单ID发行版'$errors\u query->post->ID.'剩余余额现在到期。

'; }
最后在结束循环之后

// Define the variable first and give it a default value
$error_message = null;
// Check if there are any errors to display
if($error_message != null) {
  echo '<div class="errors">'.$error_message.'</div>';
}
//检查是否有任何要显示的错误
如果($error\u message!=null){
回显“.$error_message.”;
}

Great stuff-您遇到的问题是,一旦设置$error\u消息,它就会保持不变。因此,通过将所有消息都保留在条件(if)中,那么它只会在应该显示的时候显示:)谢谢Simon,我想从长远来看,我宁愿将所有消息存储为数组(因为会有更多if语句)例如if($已支付押金!=1){-理想情况下,我只希望有一行代码,回送出所有错误-你认为这可能吗?是的,这应该是可能的-你希望每个预订都有一条错误消息还是一条与所有预订相关的大错误消息?是的,后一条,因此在页面顶部-最重要的是所有预订都有一个相关错误的列表这有意义吗?让我在问题中添加我所有的错误if语句
// Define the variable first and give it a default value
$error_message = null;
// Form not complete
if($is_form_complete !=1) {
  $error_message .= '<i class="fa fa-clock-o"></i><p>Booking form ID DISTR'.$errors_query->post->ID.' needs to be completed.</p>';
}

// Deposit due
if($is_deposit_paid !=1) {
  $error_message .= '<i class="fa fa-clock-o"></i><p>Booking form ID DISTR'.$errors_query->post->ID.' deposit now due.</p>';
}

// Full Payment due
if($is_full_amt_paid !=1) {
  $error_message .= '<i class="fa fa-clock-o"></i><p>Booking form ID DISTR'.$errors_query->post->ID.' remaining balance now due.</p>';
}
// Check if there are any errors to display
if($error_message != null) {
  echo '<div class="errors">'.$error_message.'</div>';
}