views:

68

answers:

2

I am using add post meta function to save some data and its not working

<?php
//include '../../../wp-blog-header.php';
$unique = "true";
$pageID = $_GET['postID'];
echo "pageID:";
echo $pageID;

echo "</br>";
$num_posts = $_GET['num_posts'];
echo "num_posts: ";
echo $num_posts;
echo "</br>";
$num_posts_meta_key = "num_posts";
add_post_meta($pageID, $num_posts_meta_key, $num_posts , $unique) or update_post_meta($pageID, "num_posts" , $num_posts);
?>

Can someone help me out?

A: 

not sure what your problem is.. are you sure you're passing the right postID parameter? does the post exist in the database?

You don't really need to do add_post_meta() or update_post_meta.

From the manual:

The first thing this function will do is make sure that $meta_key already exists on $post_id. If it does not, add_post_meta($post_id, $meta_key, $meta_value) is called instead and its result is returned.

<?php
// This minimum code should work, though you should really check that a post 
// with this id does exist.
update_post_meta($_GET['postID'], "num_posts" , $_GET['num_posts']);
?>
Ben
I checked in wp_postmeta table and id does exists there ....I will try what u have suggested now.
Snehal Patil
this id should exist in wp_posts
Ben
I will check in wp_post table today..I thought of debugging it...but dreamweaver doenst have debugging tool ;(
Snehal Patil
wp_posts also has post_id which i am looking for..
Snehal Patil
A: 

In first page I am getting all values from textboxes or checkboxes in javascript and then i am passing it in URL to next page where add_post_meta function is there.

I tried using method POST ...but then it doesnt work for me. It just submit the page and come back w/o doing anything on 1st page. I tried with GET method..but nothing works.

Hence I decided to take all values like num of post, post id in javascript and then from there pass it with url by using window.location.

I am very new to wordpress plugin coding. I thought POST method in my plugin is conflicting with some other post method in post.php..not sure though..

I am writing plugin for admin panel.

Snehal Patil
Sounds obscure. Your data must be going missing somewhere. Try some var_dumps in the add_meta function, user Charles HTTP Proxy to see what gets sent, etc. Sorry I can't be much help. I doubt the problem is in wordpress's code base. You must be doing something wrong before calling it.
Ben
ummm...I will try putting some var dump in add_meta function. At least will come to know that if its going inside that function or not. What do you mean by something wrong in base code..? means wordpress 3.0 code that I am using ....I took a reference of some code to build the code for plugin and then build my functionality over it. Would that cause problem?
Snehal Patil
You were great help :) I dont know anyone who can help me out with this. Thanks a lot for your suggestions!!
Snehal Patil