WordPress.org

Ready to get started?Download WordPress

Forums

Custom db-query hooked with save post? (2 posts)

  1. mahjong
    Member
    Posted 3 years ago #

    Hi all!
    I'm using the add meta box function on the post/edit page. I would like to add my special content to the database, but somehow it is not working, i can't hook my database query into save post. Here is what i'm using, please help me notice what is wrong.

    add_action('save_post', 'custom_content');
    
    function custom_content() {
            // return $post->ID;
            global $post;
            global $wpdb;
            $wpdb->query("UPDATE wp_customcontent SET fieldid = 7 WHERE ID = 2 AND postID = 10");
    
    }

    Of course i will not using this on my site, it is just for testing purposes. If i use the query in phpmyadmin, it is working, but it seems it is not happening if i just hook it to save_post.

    P.S. adding post meta is not a solution for me, please do not mention it, as i'm not saving 1-2 data, i'm saving about 17 data to one custom-content, and for every post, there are a few custom-contents related (so with 4-5 custom content, i would have to add 4 or 5 x 17 post meta field. It is simply not good, i want to save it into my own table. Thanks!

  2. mahjong
    Member
    Posted 3 years ago #

    OK, it seems i got it. I have to add a $postid to the function.

Topic Closed

This topic has been closed to new replies.

About this Topic