大佬教程收集整理的这篇文章主要介绍了从表单生成新的自定义帖子后删除自定义页面模板,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个自定义帖子类型和一个带有表单字段的自定义页面模板。用户在表单字段中输入数据和自定义元数据,提交它,使用传递给它的值生成一个新的自定义帖子。除了一件事外,一切都很好。当您提交数据时,它会删除自定义页面模板。我不知道为什么会发生这种情况,如果您能帮助我找出问题所在以及如何解决问题,我将不胜感激。
@H_403_3@/* Template name: Add Business */ global $nameError,$websiteError,etc...; if(isset($_POST['submitted'])) { if(trim($_POST['bus_name']) === '') { $nameError = 'Please enter your business name.'; $hasError = true; } else { $bus_name = trim($_POST['bus_name']); } if(trim($_POST['bus_website']) === '') { $websiteError = 'Please enter the website address for your business.'; $hasError = true; } else { $bus_website = trim($_POST['bus_website']); } etc... if(!isset($hasError)) { $business_LisTing = array( 'post_type' => 'business','post_author' => 1,'post_title' => $bus_name,'post_content' => $bus_desc,'post_status' => 'pending' ); $post_ID = wp_update_post( $business_LisTing ); add_post_Meta($post_ID,'bus_website',$bus_website,truE); etc...
HTML
@H_403_3@<div class="entry-content"><?php if(isset($emailSent) && $emailSent == truE) { ?> <div class="thanks"> <p>Thanks,your submission was sent successfully. Please allow up to 48 hours for approval.</p> </div><?php } else { the_content(); if(isset($hasError) || isset($captchaError)) { ?> <p class="error">Sorry,an error occured.<p><?php } ?> <form action="<?php the_permalink(); ?>" ID="bus_form" method="post"> <ul class="bus_form"> <li> <label for="bus_name">Business name:</label> <input type="text" name="bus_name" ID="bus_name" value="" /> <?php if($nameError != '') { ?> <span class="error"><?php $nameError; ?></span> <?php } ?> </li> <li> <label for="bus_website">Website Address:</label> <input type="text" name="bus_website" ID="bus_website" value="" /> <?php if($websiteError != '') { ?> <span class="error"><?php $websiteError; ?></span> <?php } ?> </li> etc... </ul> </form> <?php } ?>
让它工作.....
变化 - $post_id = wp_update_post( $business_lisTing );
至 - $post_id = wp_insert_post( $business_lisTing );
并添加:
`add_post_meta($post_id,'wp_insert_post',truE);
If($post_id !== 0 && !is_wp_error($post_id)){
$business_lisTing['ID'] = intval($post_id);
$post_up = wp_update_post($business_lisTing);
add_post_meta($post_id,'wp_update_post',truE);
add_post_meta($post_id,'bus_street',$bus_street,'bus_city',$bus_city,truE);
etc...
}elseif(is_wp_error($post_id)){
$error_String = $post_id->get_error_message();
echo 'ERROR: '.$error_String;
}`
以上是大佬教程为你收集整理的从表单生成新的自定义帖子后删除自定义页面模板全部内容,希望文章能够帮你解决从表单生成新的自定义帖子后删除自定义页面模板所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。