WordPress.org

Forums

Author Product Review
Bug [with Fix] Multiple Duplicate Table Entries (16 posts)

  1. hqarrse3
    Member
    Posted 1 year ago #

    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.

    http://wordpress.org/plugins/author-product-review/

  2. nicmare
    Member
    Posted 1 year ago #

    yea. i also mentioned this bug. see my screenshot: https://www.dropbox.com/s/h7fis5ihpzgkk23/Screenshot%202014-01-04%2014.01.10.png

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

  3. nicmare
    Member
    Posted 1 year ago #

    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…

  4. hqarrse3
    Member
    Posted 1 year ago #

    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);
  5. hqarrse3
    Member
    Posted 1 year ago #

    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.

  6. hqarrse3
    Member
    Posted 1 year ago #

  7. nicmare
    Member
    Posted 1 year ago #

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

  8. jh20001
    Member
    Posted 7 months ago #

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

  9. Mike Hardaker
    Member
    Posted 7 months ago #

    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

  10. hqarrse3
    Member
    Posted 7 months ago #

    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"

  11. nicmare
    Member
    Posted 7 months ago #

    haha

  12. Mike Hardaker
    Member
    Posted 7 months ago #

    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....

  13. hqarrse3
    Member
    Posted 7 months ago #

    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.

  14. hqarrse3
    Member
    Posted 7 months ago #

    There you go:

    http://www.arrse.co.uk/olive_scripts/author-product-review.php.txt

    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.

  15. Mike Hardaker
    Member
    Posted 7 months ago #

    Many thanks! hq

  16. Mike Hardaker
    Member
    Posted 7 months ago #

    mushrooms funny :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Author Product Review
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic