looking at the example on wordpress
update_post_meta( $post_id, $meta_key, $meta_value, $prev_value );
I seem to be having a problem replacing $meta_key with a variable. here is my code
Part 1
Setting the $week
<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
}
?>
If you echo $week all is ok.
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() );
}
}
If you echo $week_s1 all is ok
If you replace the the variable $week_s1 with the typed out value "_member_score_week_1_s1" the code works perfectly.Here is the example
update_post_meta($pidac, "_member_score_week_1_s1" , $_POST[$s1]);
Can someone please advise me on how I can use the ($week_s1 ) variable in this code.
looking at the example on wordpress
update_post_meta( $post_id, $meta_key, $meta_value, $prev_value );
I seem to be having a problem replacing $meta_key with a variable. here is my code
Part 1
Setting the $week
<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
}
?>
If you echo $week all is ok.
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() );
}
}
If you echo $week_s1 all is ok
If you replace the the variable $week_s1 with the typed out value "_member_score_week_1_s1" the code works perfectly.Here is the example
update_post_meta($pidac, "_member_score_week_1_s1" , $_POST[$s1]);
Can someone please advise me on how I can use the ($week_s1 ) variable in this code.
Share Improve this question asked Jul 5, 2019 at 5:06 MFWebMasterMFWebMaster 114 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 0There is an error in setting variable on this line:
$week_s1="_member_score_".$week._s1";
this line should be
$week_s1 ="_member_score_".$week."_s1";
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745343818a4623452.html
$_POST[get_the_title()."s1"]
? there is no corresponding post key for that in your form... (pspost-type
should bepost_type
) – majick Commented Jul 5, 2019 at 10:56