Hi,
I need to change ALL the custom field field values on the fly for all posts. Have tried using update_post_meta()-function and it works, but i would like this to happen only when i access a certain page or (even better) when clicking a button, maybe with jQuery AJAX. Now it changes the value even if i don't call this page, which I think is strange.
Thankful for any help!
My current page:
<?php
/*
Template name: Reset
*/
?>
<?php get_header(); ?>
<?php
$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = 'price'
AND wpostmeta.meta_value = '50'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
ORDER BY wposts.post_date DESC";
$pageposts = $wpdb->get_results($querystr, OBJECT);
?>
<?php if ($pageposts): ?>
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<?php update_post_meta($post->ID, 'price', '0'); ?>
<?php endforeach; ?>
<?php else : ?>
<?php endif; ?>
<?php get_footer(); ?>