WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. hqarrse3
    Member
    Posted 7 months 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 6 months 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 6 months 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 6 months 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 6 months 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 6 months ago #

  7. nicmare
    Member
    Posted 6 months ago #

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

Reply

You must log in to post.

About this Plugin

About this Topic