Solved

Wordpress: hide custom field array

Posted on 2014-04-25
3
381 Views
Last Modified: 2014-05-25
Hi,

I want to hide a number of custom fields in the custom field metabox that my users should not be messing with. Just leave the ones they should enter something into.

I found this filter that will hide one custom field:

add_filter( 'is_protected_meta', 'hide_feelings', 10, 2 );
function hide_feelings( $protected, $meta_key ) {
      if ( 'feelings' == $meta_key ) return true;
      return $protected;
}

Is there a way that I can use that but hide a number of fields?

So, for example, if I have:

$mk = array('approver','approver_1','cf_fields','cf_rules');

It would hide all those fields from users?

Thanks for any help,

Chris
0
Comment
Question by:St_Aug_Beach_Bum
  • 2
3 Comments
 
LVL 25

Expert Comment

by:lenamtl
ID: 40032365
Do you mean grayed fields with visible info (not editable but visible) or completely invisible fields?
0
 

Accepted Solution

by:
St_Aug_Beach_Bum earned 0 total points
ID: 40077572
Sorry for the very late reply. Actually worked this out with an &&

ie:

if (('feelings' !== $meta_key) && ('feelings2' !== $meta_key)) return true;

Seems like that should have to be an ||, but this is what works.....

hmm.

Thank you for offering to help though.

Chris
0
 

Author Closing Comment

by:St_Aug_Beach_Bum
ID: 40089274
Found own solution.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The viewer will learn how to count occurrences of each item in an array.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question