查看wordpress上的示例。组织机构
update\\u post\\u meta($post\\u id,$meta\\u key,$meta\\u value,$prev\\u value);
我似乎在用变量替换$meta\\u键时遇到了问题。这是我的密码
Part 1
设置$周
<form action="#" method="post">
<select name="Week">
<option value="week_1">1</option>
<option value="week_2">2</option>
<option value="week_3">3</option>
<option value="week_4">4</option>
<option value="week_5">5</option>
<option value="week_6">6</option>
<option value="week_7">7</option>
<option value="week_8">8</option>
</select>
<button class="btn btn-lg btn-primary" type="submit" name="submit" value="Selected a Week" >Selected a Week</button>
</form>
<?php
if(isset($_POST[\'submit\'])){
$week = $_POST[\'Week\']; // Storing Selected Value In Variable
echo "You have selected : ".$week." to be edited"; // Displaying Selected Value
}
?>
如果你回显$周,一切都好。
Part 2
$current_post = $post->ID;
$title = get_the_title();
$s1 = $title . "s1";
$week_s1 = "_member_score_".$week._s1";
$post_information = array(
// Look at this //
\'ID\' => $current_post,
\'post_title\' => $title,
\'post-type\' => \'CTP-Name\',
\'post_status\' => \'publish\',
);
$pidac = wp_update_post($post_information);
if($pidac)
{
update_post_meta($pidac, $week_s1, $_POST[$s1]);
$term_ids = array( 2, 7 );
$taxonomy = \'Custom-Taxonomy\';
wp_set_object_terms( $pidac, $term_ids, $taxonomy );
// Redirect
wp_redirect( home_url() );
}
}
如果您回显$week\\u s1,一切正常
如果将变量$week\\u s1替换为键入的值“\\u member\\u score\\u week\\u 1\\u s1”,则代码工作正常。下面是一个例子
update_post_meta($pidac, "_member_score_week_1_s1" , $_POST[$s1]);
有人能告诉我如何在这段代码中使用($week\\u s1)变量吗。