Hide custom fields by user’s role

You can use the current_user_can() function to test the current user’s role. I would also recommend making the custom field protected by default and allowing access only to the proper users. In theory, something like this should work: function my_exclude_custom_fields( $protected, $meta_key) { if ( in_array( $meta_key, array( ’email’, ‘text’ ) ) ) { if … Read more

a lot of custom fields

Like Joel M asked, it really depends on what you mean by “a lot of posts”. It also depends a lot on if you’re querying these posts in complicated ways. I highly recommend you install the plugin Query Monitor (https://wordpress.org/plugins/query-monitor/). It will tell you how long various queries are taking. You can then create “a … Read more

How do I display a custom field in an existing form on the front end?

This worked for me: In the template file (used with that existing form), before the get_header(); call/line, add this code: global $my_dates_MB; // If you changed the meta box ID (i.e. mydates), change it also below. add_filter( ‘rwmb_show_mydates’, ‘__return_false’ ); $meta_boxes = get_dates( [] ); $my_dates_MB = rwmb_get_meta_box( $meta_boxes[0] ); if ( isset( $_POST[‘my_dates_post_ID’] ) … Read more

Permanently show Custom Fields in Editor

this should work but you overwrite the values for existing objects. to add default values only for new objects try that : $postType = “tender”; add_action( ‘save_post_’ . $postType, function ($post_ID, \WP_Post $tender, $update) { if (!$update) { // default value for new object // Add the meta data you want the custom post type … Read more

Sort columns in the ‘Pages’ dashboard overview

I just realized that there was a typo in the code. The meta-tag should read ‘prod_hierar’ instead of ‘prod-hier’. This fixes the issue. (Too much experimenting, I guess ..). Function ‘wms_hierarchy_col_orderby()‘ thus becomes: function wms_hierarchy_col_orderby( $vars ) { if ( isset( $vars[‘orderby’] ) && ‘prod_hierar’ == $vars[‘orderby’] ) { $vars = array_merge( $vars, array( ‘meta_key’ … Read more