WordPress.org

Forums

Get Custom Field Values
order of list (3 posts)

  1. zhiwan
    Member
    Posted 3 years ago #

    Hi. Does anyone happen to know how the "c2c_get_current_custom" orders the information? I have a number of "Team Members" custom field in each post that the plugin grabs and it does it correctly, but not in any order that I can discern. It isn't alphabetical, nor is it in the order that I entered the data. So how is it doing it? And the 'order' function only works for the 'c2c_get_recent'. Any help in the right direction would be nice.

    http://wordpress.org/extend/plugins/get-custom-field-values/

  2. zhiwan
    Member
    Posted 3 years ago #

    No one knows? I just need to know if I can control the order that the plugin is grabbing multiple pieces of data from one custom field. Thanks.

  3. Scott Reilly
    WordPress & Plugin Dev
    Plugin Author

    Posted 3 years ago #

    The function c2c_get_current_custom() relies on WordPress's get_post_custom_values() function. The latter performs a query without specifying an ORDER BY clause in the SQL, so the order of the data returned cannot be depended on (as you've noticed).

    Presumably you'd expect/prefer the custom field values to be ordered alphabetically?

    In thinking about it, it seems like it may be worthwhile for me to allow specifying an 'order' argument to a few of the functions. In the meantime, there isn't a straightforward solution for you. Depending on where and how you're using the function, you can invoke the output formatting function directly with the sorted custom field values.

    For example, Instead of something like this:

    echo c2c_get_current_custom( 'myfield', '', '', '', ', ' );

    You'd do:

    $cfvalues =  (array) get_post_custom_values( 'myfield', get_the_ID() );
    sort( $cfvalues );
    echo c2c__format_custom( 'myfield', $cfvalues, '', '', '', ', ' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic