I’m creating a very basic WordPress plugin whose purpose is to display a numerical value beside each post.
My Logic for the plugin function (plugin.php) is this:
<?php
function foo($post_id){
$somevalue=1 //Some random value
add_post_meta($post_id, 'posts_numericalvalue', '0', true) or update_post_meta($_post_id, 'posts_numericalvalue', $somevalue);
}
add_action('post_save', 'foo');
?>
And in my template’s index.php, I have (inside the loop):
<?php
....
printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0'));
$numerical_val = get_post_meta($post->ID, posts_numericalvalue);
echo 'this post has a value of ' .$numerical_val;
....
?>
1) The code above is obviously not working. I think its because my function in plugin.php requires me to pass the current post’s ID, but the action hook doesn’t pass the post’s current ID I guess (correct me if I’m wrong). How do I pass the post ID to my function inside plugin.php using an action hook?
2) Any other elegant way of doing this? I just need to assign my posts with a numerical value which should be updated with 1 if the post already has one, zero if the post hasn’t got one already.
Any help is much appreciated. Thanks.