Piklist allows you to lock a field value (making it read-only), when the post status changes. A perfect example of this is if you want to lock post meta once a post is published.

Here’s how we do that:

If you are already using Piklist, then skip to step 4.

  1. Install Piklist
  2. Decide if you are going to build your Piklist code as a plugin or in your theme.
  3. With Piklist you can display fields as metaboxes, on a Settings page or a Widget. Choose which one you want to use.
  4. Create your field the standard Piklist way.  For this tutorial we will create a text box.  The only difference is that you will add the on_post_status parameter. You’ll notice that it is set to show values when the post status equals publish.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    piklist('field', array(
      'type' => 'text'
      ,'field' => 'text_no'
      ,'label' => 'Sample field locked'
      ,'value' => 'Not editable'
      ,'help' => 'This is help text.'
      ,'attributes' => array(
        'class' => 'text'
      )
      ,'on_post_status' => array(
        'value' => 'publish'
      )
    ));

Believe it or not, that’s it!

 

Show Values on different Post Statuses

You can also show values on a post status, or a group of post statuses.

    1. First register and create post statuses as described in this tutorial.
    2. Using this example, and the code above, you can show values on a group of post statuses by separating them with a comma. The example below will show values on the post statuses “repair-declined” and “closed”.
1
2
3
4
5
6
7
8
9
10
11
12
13
piklist('field', array(
  'type' => 'text'
  ,'field' => 'text_no'
  ,'label' => 'Sample field locked'
  ,'value' => 'Not editable'
  ,'help' => 'This is help text.'
  ,'attributes' => array(
    'class' => 'text'
  )
  ,'on_post_status' => array(
    'value' => 'repair-declined','closed'
  )
));

 

Show Values on a range of Post Statuses

You can also show values on a range of post statues.

    1. First register and create post statuses as described in this tutorial.
    2. Using this example, and the code above, you can show values on a range of statuses by using double hyphens as the separator: -- The example below will show values for ALL STATUSES BETWEEN “repair-declined” and “closed”.
1
2
3
4
5
6
7
8
9
10
11
12
13
piklist('field', array(
  'type' => 'text'
  ,'field' => 'text_no'
  ,'label' => 'Sample field locked'
  ,'value' => 'Not editable'
  ,'help' => 'This is help text.'
  ,'attributes' => array(
    'class' => 'text'
  )
  ,'on_post_status' => array(
    'value' => 'repair-declined--closed'
  )
));