admin管理员组文章数量:1414908
How can I update post meta inside the WP_Query? Does this mean inside the loop? Sorry, I'm not too technical about this.
This is the code I'm using:
<?php
if(isset($_POST['jolly'])){
update_post_meta($post->ID , 'carry', 3);
}
?>
<form action='' method='POST'>
<input type='submit' name='jolly' value='test' />
</form>
Are there alternative ways?
How can I update post meta inside the WP_Query? Does this mean inside the loop? Sorry, I'm not too technical about this.
This is the code I'm using:
<?php
if(isset($_POST['jolly'])){
update_post_meta($post->ID , 'carry', 3);
}
?>
<form action='' method='POST'>
<input type='submit' name='jolly' value='test' />
</form>
Are there alternative ways?
Share Improve this question edited Nov 12, 2016 at 20:25 Dave Romsey 17.9k11 gold badges56 silver badges70 bronze badges asked Nov 12, 2016 at 20:15 user106861user1068611 Answer
Reset to default 1The Loop is PHP code used by WordPress to display posts. You can see how a loop is constructed on generatewp.
// WP_Query arguments
$args = array ();
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while( $query->have_posts() ) {
$query->the_post();
$post = get_post();
if ( isset( $_POST[ 'jolly' ] ) ) {
update_post_meta( $post->ID, 'jolly', $_POST[ 'jolly' ] );
}
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();
?>
<form action='' method='POST'>
<input type='submit' name='jolly' value='test'/>
</form>
本文标签: wp queryHow can I update post meta inside a WPQuery loop or the WordPress loop
版权声明:本文标题:wp query - How can I update post meta inside a WP_Query loop or the WordPress loop? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745177086a2646289.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论