Home Forums Plugin Support WP User Frontend Pro Repeatable fields get messed up each time a post is updated

This topic is: resolved

This topic contains 6 replies, has 2 voices, and was last updated by  cob-web 5 years, 9 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #7586

    cob-web
    Participant
    Post count: 14

    Hi Tareq,

    I set up a repeatable field called ‘credits'. When inserting credits, the actual order is very important (e.g director, camera, music etc).
    Each time I save a post, the order gets messed up. Also in the frontend the credits show in rather random order.
    The edit in this post doesn't make a difference to me: http://wedevs.com/support/topic/repeat-field-out-of-order/

    I made some digging and found this
    http://wordpress.org/ideas/topic/add-order-by-meta_id-to-update_meta_cache
    but not sure if it has something to do with it.

    Do you have a hint?
    Thanks!

    #7592

    cob-web
    Participant
    Post count: 14

    I think I've found a solution for the frontend:

    
    <?php $myid = $post->ID; 
                            $data = $wpdb->get_results("
                            SELECT * FROM $wpdb->postmeta WHERE post_id = $myid
                            AND meta_key NOT LIKE '\_%'
                            AND meta_key  IN('additional_credits')
                            ORDER by meta_id ASC
                        ");
    
                        if( !empty( $data ) ) {
                        foreach( $data as $result_object ) {
          
    				$values = explode( '| ', $result_object->meta_value);
            $role_additional = "{$values[0]}";
            $url_additional = "{$values[2]}";
    		if ($role_additional == '')
    { ?>
    <?php } else { 
    if ($url_additional  == '') // link to url when available
    { echo "{$values[0]}: {$values[1]} <br />"; } else { 
    echo "{$values[0]}: <a target=\"blank\" href=\"$url_additional\">{$values[1]}</a><br />"; 
     	} 
      }
    }}
    ?>	

    But I still worry about the backend, as my client doesn't like the idea of “random changing” ๐Ÿ˜‰
    Any idea on that would be very appreciated!

    #7601

    cob-web
    Participant
    Post count: 14

    I just found out, that each time a post is updated the repeatable fields get saved for new! It means each time the meta_id of it increases! Is this normal? Is it the way it works? It's at 17632 now and growing…. This actually kind of explains the problem with the reordering: when I create a group of ordered fields, each time I update the post, they get reordered and saved for new.
    Is it a “normal” behaviour? ๐Ÿ˜‰
    Thanks in advance.

    #7630

    Tareq Hasan
    Keymaster
    Post count: 2831

    Yeah, that was normal behavior. Because as you've said, get meta functions doesn't provide you the meta ID's. So when you are going to update those, there is no way to know if you are updating the same items or you are adding a new item. So the little trick was to delete all existing and adding the items again.

    #7637

    cob-web
    Participant
    Post count: 14

    Thanks Tareq!
    One more question to this: is it also normal, that from time to time a new row of fields appears? I mean, I press “update” and suddenly there is an empty row of repeatable fields. I have to press the “-” to delete it. Have you experienced this?

    #7641

    Tareq Hasan
    Keymaster
    Post count: 2831

    No, I haven't faced that issue. May be I need to recheck.

    #7642

    cob-web
    Participant
    Post count: 14

    All right then. I'm also using WPML, which doesn't seem to be 100% compatible with your plug-in. I'll keep an eye on that.
    Thanks.

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Repeatable fields get messed up each time a post is updated’ is closed to new replies.