Display Custom Field per Page Template

First off, this is an awesome theme and I am having fun working with it. Lots of helpful posts on the forum as well, so thank you!!

I am attempting to use this http://www.getbeans.io/code-reference/functions/beans_register_post_meta/ documentation however clearly I could use some help! Thanks in advance!

I am having trouble displaying custom fields per page templates. This is what I have right now.

beans_register_post_meta( $fields, array( 'page' ), 'hero-section', array( 'title' => __( 'Hero Content' ) ), $conditions, array('home-template.php' )

Hi Leah,

Here is an example how you would register post meta for a specific template file named example-template.php:

add_action( 'admin_init', 'example_register_post_meta' );
 * Register example post meta
function example_register_post_meta() {

 $fields = array(
      'id'         => 'example',
      'label'      => __( 'Example', 'example-domain' ),
      'type'       => 'text',

  beans_register_post_meta( $fields, array( 'example-template.php' ), 'example_section_id', array(
    'title' => 'Example',
 ) );


Refering to the API documentation for the beans_register_post_meta() function, the second argument may be an array of post types ids, post ids or page template slugs. Note how we use example-template.php (change it with your template slug) in the example above which will display the registered post meta only when that template is selected.

Happy coding,

Super, thank you, I will give this a try!

Write a reply

Login or register to write a reply, it's free!