Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • Programming
    • C
    • C++
    • Java
  • Web Development
    • Java Script
    • jQuery
    • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • Programming
    • C
    • C++
    • Java
  • Web Development
    • Java Script
    • jQuery
    • PHP

Custom fields: In what order are they saved into the DB?

The SQL query triggered by get_post_custom() is in update_meta_cache() and it looks like this:

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

So there is no ORDER BY given.

Without ORDER BY the resulting order is almost unpredictable: it depends on the optimizer, used indexes and their order.

The order the fields are saved doesn’t matter here.

You can filter 'query' and add an ORDER BY clause to the query. See wp-includes/wp-db.php – wpdb::query() for details.

Categories custom-field Tags custom-field, post-meta
Post navigation
Display specific WooCommerce products to different types of users
Change labels of custom post type via child theme

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Multisite – user email activation links broken
  • Add fields in customization tab to change background colours of certain classes
  • WordPress post_where & posts_join not working only for custom post type
  • Custom post type: Disable single page, but keep archive
  • What is the meta field in the response of the user REST API?
  • WP_Query Check if post has one or more attached medias
  • Cannot DIsplay a Snackbar Notice on Button Click – Notice is undefined
  • How to save checkbox values for logged in users?
  • export a csv file from the database with a cronjob
  • Store data from nested block of gutenberg
© 2022 Read For Learn
  • Programming
    • C
    • C++
    • Java
    • javascript
    • Python
    • R
  • Web Development
    • Java Script
    • jQuery
    • PHP
    • WordPress
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Microsoft Office
  • modx
  • root
  • Tips & Trick
  • Tools
  • windows