Developer's Custom Fields
[resolved] Retrieving key names and key/value pairs (3 posts)

  1. timboreader
    Posted 2 years ago #

    Sorry if this is in the docs but I can't find it.

    Is it possible to loop through all slt custom fields and retrieve their keys as well as their values?

    This function, I think, only retrieves the values of the fields: slt_cf_all_field_values()

    I would like to do two things:
    (1) Retrieve a list of the keys on their own (to output in a list)
    (2) Retrieve the keys at the same time as the values so I can assign them a css classname

    Even better would be able to retrieve the human readable 'label' as assigned when the fields are registered, which labels the fields at the back end. Can these be retrieved at the front end?

    Many thanks



  2. Steve Taylor
    Plugin Author

    Posted 2 years ago #

    Hi Tim,

    I've never come across an instance where this might be necessary, but...

    There's a function used internally: slt_cf_get_field_names( array('post'), array('text','textarea' ) ) - this instance would get the field names for all text and textarea fields assigned to posts. But it's global - it doesn't filter according to the current post.

    There's also slt_cf_get_current_fields(), which will get the fields applied to the current object. It returns the full field definition array, including of course the name/key.

    Past that, you can access the global variable $slt_custom_fields to access all the registered information.

    Check the source - you should be able to get what you want with the above info!



  3. timboreader
    Posted 2 years ago #

    Hi Steve,
    Many thanks indeed for that info - I managed to achieve what I was aiming for, albeit not necessarily in the same elegant way I'd first envisaged!
    When the page is live I'll write a blog post about what I did, as I do believe others may try to do achieve something similar.
    I've set the topic to 'resolved'.
    Thanks again

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Developer's Custom Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic