WordPress.org

Ready to get started?Download WordPress

Forums

Add order by meta_id to update_meta_cache (1 post)

  1. donatien
    Member
    Posted 3 years ago #

    As of now get_post_meta returns value pairs in random order when used with multiple custom fields with the same key. It would be useful to either get the meta_id back for manual sorting or (better) having the result set returned ordered by meta_id which is the order they were entered.

    Ran into trouble when I tried to match up several "pairs" of custom fields with same keys and fixed it by changing line 294 of /wp-includes/meta.php to:

    $meta_list = $wpdb->get_results( $wpdb->prepare("SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list) order by meta_id", $meta_type), ARRAY_A );

    Simply added the "order by meta_id"..

Topic Closed

This topic has been closed to new replies.

About this Topic