Support » Plugin: Author Product Review » Bug [with Fix] Multiple Duplicate Table Entries

  • I believe this is a bug, although doesn’t affect functionality. Every time you edit and save an article a new set of meta data is added, so filling the meta database unnecessarily.

    If you therefore click on “Screen Options” and tick “Custom Fields” when editing a post, you get a long list of duplicates, 4 for every time the article is saved.

    The reason for this is that WP function update_post_meta return false if the data already exists (see below), but in the plugin in the case that data already exists the false from update_post_meta is assumed to mean that the data doesn’t exist, and add_post_meta is then called and a duplicate created. This is around line 208 in author-product-reviews.php.

    The fix is just to remove the 4 conditional calls to add_post_meta.


    From WP codex, for update_post_meta:

    Returns meta_id if the meta doesn’t exist, otherwise returns true on success and false on failure. It also returns false if the value submitted is the same as the value that is already in the database.

Viewing 15 replies - 1 through 15 (of 15 total)
  • nicmare


    yea. i also mentioned this bug. see my screenshot:

    thank you for the fix! seems to work although i dont feel good to comment out so much code 😉



    update: i knew it would not be a good idea to remove so much code. now it does not save the custom fields on news posts. it only solves the duplicate fields on existing posts but now it does not work on new posts…



    then you’ve commented the wrong thing as it works fine. You should be commenting out the add_post_meta lines – I thought you were being a little melodramatic with “so much code”. You should be left with:

    update_post_meta($post_id, 'schema_product_name', $productName);
    update_post_meta($post_id, 'schema_product_price', $productPrice);
    update_post_meta($post_id, 'schema_price_currency', $priceCurrency);
    update_post_meta($post_id, 'schema_rating', $rating);


    the reason this works without add_post_meta is (from the codex):

    This may be used in place of add_post_meta() function. 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.



    Just made a mistake above – note my post has been edited



    ah got it now! i commented out all the lines before instead of updating them ;-). seems to work right now. thank you hqarrse3!

    Thanks for the update. I’ve been wondering how to get rid of that >_<

    Is this really the solution. Asking people to go in and change code in WordPress so the Plugin will play nicely? This needs to be fixed ASAP

    I think the words you were looking for were:

    “thanks Rajesh Namase for taking the time and trouble to post your code and documentation for others to use for free, and thanks hqarrse3 and nicmare for sorting out a bug and posting the discussion to help others”

    followed perhaps by

    “It looks as thought the author has moved on, and I think the community can do better, so I’m going to take this project on and (with the permission of Rajesh)” release a new version”


    Yeah this great info for people that know how to code. Want me how to tell you how to do a tuneup on your car? Think a newbie would be best going under the hood?

    “The fix is just to remove the 4 conditional calls to add_post_meta.” and where o where might this live. Again just pull the spark plugs out and put the wires back on….

    I would have to pay you to tune up my car as I don’t have the time or know-how. Likewise if you don’t have the time or know-how to adjust this modification to suit your needs, then you need to pay someone who does.

    Looking at free / pro bono – just the same as I wouldn’t complain if you did a less-than-perfect free tune-up for me, you should stop griping about less-than-perfect free coding work.

    All that aside I can send you the file with the fixes in place if that helps.

    There you go:

    Just replace the file with the same name in wp-content/plugins/author-product-review/ after removing the .txt from the end. That’s there just to stop my server trying to execute the file.

    Many thanks! hq

    mushrooms funny 🙂

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Bug [with Fix] Multiple Duplicate Table Entries’ is closed to new replies.