我正在为Wordpress构建CRM主题。所以我在前端发布、编辑和删除帖子。我想我正在寻找一种解决所有问题的好方法。但有一个失败。在索引处有一个“编辑”和“删除”按钮。如果我点击“编辑”,我将进入一个表单。我可以在那里更改post\\u标签。更改将被保存,但单个单词不会分开。输入字段中的所有单词都是一个巨大的标记-我可以在侧栏的小部件中看到它。但我用分隔符。。。如果您有2分钟:
在这里(index.php中),我可以删除一篇帖子:
if( \'POST\' == $_SERVER[\'REQUEST_METHOD\'] ) {
set_query_var( \'postid1\', $_POST[\'postid\'] ); /* set the "postid" value from the delete button of the post we choose to delete into "postid1" */
wp_delete_post( get_query_var( \'postid1\'), true ); /* delete the post we choosed */
};
get_header(); ?>
在索引的循环中,您可以找到以下代码段。第一个表单用于编辑,第二个表单用于删除:
<form class="edit" action="<?php echo esc_url( home_url( \'/\' ) ); ?>editieren-formular/" method="post">
<input type="hidden" name="postid" value="<?php the_ID(); ?>" /> <?php /* get the post ID into "postid" and later pass it to "editieren-formular.php" */ ?>
<input type="submit" value="Edit" />
</form>
<form class="delete" action="" method="post">
<input type="hidden" name="postid" value="<?php the_ID(); ?>" /> <?php /* get the post ID into "postid" and later delete the post */ ?>
<input type="submit" value="Delete" />
</form>
一切都很好。现在是编辑公式。php是一个站点的页面模板,称为“Editiere Formular”。“editieren formular”是鼻涕虫。
<?php
/*
Template Name: Editieren Formular
*/
if( \'POST\' == $_SERVER[\'REQUEST_METHOD\'] && !empty( $_POST[\'action\'] ) && $_POST[\'action\'] == "edit_post" && isset($_POST[\'postid\'])) {
$post_to_edit = array();
$post_to_edit = get_post($_POST[\'postid\']);
/* these are the fields that we are editing in the form below. */
$title = $_POST[\'title\'];
$description = $_POST[\'description\'];
$vorname = $_POST[\'vorname\'];
$name = $_POST[\'name\'];
/* this code will save the title and description into the post_to_edit array */
$post_to_edit->post_title = $title;
$post_to_edit->post_content = $description;
/* honestly i can\'t really remember why i added this code but it is a must */
$pid = wp_update_post($post_to_edit);
/* save taxonomies: post ID, form name, taxonomy name, if it appends(true) or rewrite(false) */
wp_set_post_terms($pid, array($_POST[\'cat\']),\'firmen\',false);
wp_set_post_terms($pid, array($_POST[\'post_tags\']),\'post_tag\',false);
//UPDATE CUSTOM FIELDS WITH THE NEW INFO
//CHANGE TO YOUR CUSTOM FIELDS AND ADD AS MANY AS YOU NEED
update_post_meta($pid, \'vorname\', $vorname);
update_post_meta($pid, \'name\', $name);
//REDIRECT USER WHERE EVER YOU WANT AFTER DONE EDITING
wp_redirect( \'http://crm-wordpress-theme.wellseo.de\' );
...
} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM
get_header();
$post_to_edit = get_post($_POST[\'postid\']);
$terms = get_the_terms($post_to_edit->ID, \'firmen\');
$tags = strip_tags( get_the_term_list( $post_to_edit->ID, \'post_tag\', \'\', \', \', \'\' ) );
<?php $term_name = strip_tags( get_the_term_list( $post_to_edit->ID, \'category\', \'\', \', \', \'\' ) ); ?> <!-- get the category name of this post -->
<?php $term_obj = get_term_by(\'name\', $term_name, \'category\'); ?> <!-- get the current term object -->
<?php $term_id = $term_obj->term_id ;?> <!-- get this post\'s term id -->
<?php $args = array(
\'selected\' => $term_id,
\'name\' => \'cat\',
\'class\' => \'postform\',
\'tab_index\' => 10,
\'depth\' => 2,
\'hierarchical\' => 1,
\'hide_empty\' => false ); /* array for wp_dropdown_category to display with the current post category selected by default */ ?>
<div id="content" role="main">
<form id="edit_post" name="edit_post" method="post" action="" enctype="multipart/form-data">
<fieldset name="title">
<label for="title">Title:</label><br />
<input type="text" id="title" value="<?php echo $post_to_edit->post_title; ?>" tabindex="5" name="title" />
</fieldset>
<fieldset id="category">
<label for="cat" ><?php wp_dropdown_categories( $args ); ?></label>
</fieldset>
<fieldset class="content">
<label for="description">Discount Description:</label><br />
<textarea id="description" tabindex="15" name="description"><?php echo $post_to_edit->post_content; ?></textarea>
</fieldset>
<!-- BELOW ARE THE CUSTOM FIELDS -->
<fieldset class="vorname">
<label for="vorname">Vorname:</label><br />
<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,\'vorname\', true); ?>" id="vorname" tabindex="20" name="vorname" />
</fieldset>
<fieldset class="name">
<label for="name">Name:</label><br />
<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,\'name\', true); ?>" id="name" tabindex="20" name="name" />
</fieldset>
<fieldset class="tags">
<label for="post_tags">Additional Keywords (comma separated):</label><br />
<input type="text" value="<?php echo $tags; ?>" tabindex="35" name="post_tags" id="post_tags" />
</fieldset>
<fieldset class="submit">
<input type="submit" value="Speichern" tabindex="40" id="submit" name="submit" />
</fieldset>
<input type="hidden" name="postid" value="<?php echo $post_to_edit->ID; ?>" />
<input type="hidden" name="action" value="edit_post" />
<input type="hidden" name="change_cat" value="" />
<?php // wp_nonce_field( \'new-post\' ); ?>
</form>
</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_sidebar(\'two\'); ?>
<?php get_footer(); ?>