Skip Navigation

[Resolved] Reorder the custom fields after creation

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 5 replies, has 2 voices.

Last updated by kennyP 7 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#529950

Hi everyone,

I have a question using Types.
I am using the free version of it. I have created a custom post type with a couple of fields.

I have created my own shortcode to display the data in an html table. I am using the "get_post_custom" function of wordpress to display every fields. This works fine, but it display it in the order the fields were created. So if I want to reorder the fileds, I can't. Even if I try to reoder the fields in the backend, it's always displaying it in the original order on the front end.

Anything I can do to reorder it on the front end too?
Maybe there is another function I can use? I know "types_render_field", buit this is only for a specific field. I wat to access all of them dynamically. Any idea?

Thanks!

#530146

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Kenny

You can use get_post_custom to retrieve all the meta of a post, or get_post_meta (https://developer.wordpress.org/reference/functions/get_post_meta/) when specifying only the post_id.

Neither function accepts any arguments for ordering the custom fields (they are presumably returned in the order they are stored in the database, i.e. the order they were created).

You don't specify how you want to sort them, but you will need to perform the sort after they have been retrieved and before you display them, using a PHP array sorting function, as described here: hidden link

#530338

Hi Nigel,

Thanks for your reply.

What you described here is exactly what I am doing right now, But i'm trying to find a way to have the same order in the front end than in the back end. I can really easily reorder the fields by "Drag n Drop" in the backend with toolset, but I can't find any way to have the same order in the front end.

Using your method, I can reorder by myself, but I don't have any way to reproduce the same order as the backend.

If toolset can reorder the fields that way in the backend, there is certainly a data somewhere in the database or a function that I can use to do the same on the frontend, no?

Thanks again!

#530439

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Kenny

You will still need to re-order the post meta fields after they have been retrieved, but if you want to match the order from your back end settings in Toolset > Post Fields you will find that order stored like so:

The Post Field Group is stored as a post in wp_posts with post_type 'wp-types-group'.

When you are editing the post field group in the back end you can see the id of that post in the URL bar, e.g. /wp-admin/admin.php?page=wpcf-edit&group_id=188

If you then check the corresponding wp_postmeta for that post you will find an entry with key "_wp_types_group_fields" which stores the fields in order.

#530549

Hi,

Thanks again for your help. I really appreciate it!

Ok, so I see what you are talking about. The meta_value of the meta_key "_wp_types_group_fields" for my group_id 2946 is listing all the custom field in the same order as the admin show. I see it in the database. Great!

But now, is there any way I can access this data in my code?
I only need to have access to this meta_value and I'll be all set to do the rest. That's the last piece of the puzzle for me.

Again, thanks a lot!

#530558

EDIT : Nevermind, I missread your answer. I can get it using "get_post_meta(2946)". That's fine.

Problem solved. Thanks!!! 🙂

The forum ‘Types Community Support’ is closed to new topics and replies.