Skip Navigation

[Resolved] How to give a value to new custom fields of old post types

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by francoisP-6 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1332591

Hi,

I have a post type, with a hundred of posts.

I want to add a checkbox, "featured" so that I can order them in a view : featured first and then by creation date.

If I introduce a new custom field, checkbox type and attribute the group to my old post type, I have to set manully which posts are featured, which is normal. But if I do not re-save old non-featured post, they are not showed in the list which is a bit inconvenient.

Hence my question : How to create a new checkbox custom field and give it a default value so that old post appear in queries sorted by that field, w/o reserving them all ?

Thanks !

#1332883

Hi, there's not a straightforward way to do this within Toolset. You can set a default value in some custom field, but without resaving a post where that field exists, the default value will not be applied to that post automatically. There are a few options to consider:
1. A custom database script that inserts the default values everywhere necessary
2. A 3rd-party plugin that allows you to bulk-edit custom field values from the dashboard in wp-admin. I can't vouch for the effectiveness of any of these plugins unfortunately, as they are not created by Toolset, but some claim to expose custom fields in the bulk-edit interface. That could help speed up your editing.
3. Use custom code to modify the query programmatically to test whether or not a value exists using the comparison operator EXISTS. We offer the wpv_filter_query API for this purpose: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

Let me know if you have questions about those options.

#1333137

Thanks Christian,

I will go the SQL update way.
Could you point me where the custom fields are stored in WP ?

Thanks.

F.

#1334457

Types fields are all stored in the postmeta table. In the database, you will see that the fields all have a 'wpcf-' prefix. So if the field slug in wp-admin is "color" then it will be "wpcf-color" in the postmeta table.

#1334465

My issue is resolved now. Thank you!