hero content (post meta) not saving?


Hi,

New to the Beans Framework (previous experience with wordpress/templates and static html/ccs) and trying to get myself up to speed. 🙂

I was following a thread inside the support section ( https://community.getbeans.io/discussion/how-do-i-build-a-page-structure/ ) to have a play in my wordpress staging environment. Despite the 'hero content' section registering and displaying just fine in the page editor, I can not get the hero content to save. Everytime I leave the editor and come back the fields are blank. Subsequently none of the hero content is getting rendered, from which i assume it doesn't save the hero image.

I have tried to get it working but I don't know what is going wrong. Any help appreciated!


Can you please provide your staging url and sample code? Thanks


Hi Maurice,

Tried to edit the post, and now the post disappeared on my side but I'm not allowed to post again as the post is seen as a duplicate? (confused), so trying again with this added.

staging is at: http://dev-staging.herbscience.co.nz/

The sample code in 'functions.php' was exactly the same as the url in the post above. Although for the moment I have placed the images/video staticly in the appended html as I could get the 'post meta' to work.

It displays the fields in the back-end in the page editor, but the information I enter does not get saved.

<?php

// Include Beans. Do not remove the line below.
require_once( get_template_directory() . '/lib/init.php' );

add_action( 'beans_uikit_enqueue_scripts', 'example_enqueue_uikit_assets' );

function example_enqueue_uikit_assets() {

 // Enqueue UIkit necessary extra components.
  beans_uikit_enqueue_components( array( 'flex', 'contrast' ) );

  // Enqueue child theme style.less
 beans_compiler_add_fragment( 'uikit', get_stylesheet_directory_uri() . '/style.less', 'less' );

}

add_action( 'admin_init', 'example_register_post_meta', 8 );

function example_register_post_meta() {

 $fields = array(
    array(
      'id' => 'beans_child_hero_image',
     'label' => __( 'Hero Image', 'beans-child' ),
     'type' => 'image'
   ),
    array(
      'id' => 'beans_child_hero_title',
     'label' => __( 'Hero Title', 'beans-child' ),
     'type' => 'text'
    ),
    array(
      'id' => 'beans_child_hero_button_text',
     'label' => __( 'Hero Button Text', 'beans-child' ),
     'type' => 'text'
    ),
    array(
      'id' => 'beans_child_hero_button_href',
     'label' => __( 'Hero Button Link', 'beans-child' ),
     'type' => 'text'
    )
 );

  beans_register_post_meta( $fields, array( 'post', 'page' ), 'beans-child-hero', array( 'title' => __( 'Hero Content', 'beans-child' ) ) );

}

add_action( 'wp', 'example_setup_document' );

function example_setup_document() {

 // Only apply to non-singular view.
 if ( !is_singular() ) {

   // Add grid.
    beans_wrap_inner_markup( 'beans_content', 'beans_child_posts_grid', 'div', array(
     'class' => 'uk-grid uk-grid-match',
     'data-uk-grid-margin' => ''
   ) );
    beans_wrap_markup( 'beans_post', 'beans_child_post_grid_column', 'div', array(
      'class' => 'uk-width-large-1-3 uk-width-medium-1-2'
   ) );

    // Move the posts pagination after the new grid markup.
   beans_modify_action_hook( 'beans_posts_pagination', 'beans_child_posts_grid_after_markup' );

  }

}

add_action( 'beans_header_after_markup', 'example_hero' );

function example_hero() {

 // Stop here if not image is set. We use get_queried_object to get the right id if a page is assigned to Blog Posts.
  if ( !$image_id = beans_get_post_meta( 'beans_child_hero_image', false, beans_get( 'ID', get_queried_object() ) ) )
   return;

 $image = wp_get_attachment_image_src( $image_id, 'full' );

  // Stop here if the image doesn't exist.
 if ( empty( $image[0] ) )
   return;

 ?>
  <div class="tm-hero uk-cover uk-position-relative">
   <img class="uk-width-1-1" src="<?php echo esc_url( $image[0] ); ?>" width="<?php echo esc_attr( $image[1] ); ?>" height="<?php echo esc_attr( $image[2] ); ?>">
   <div class="uk-position-cover uk-flex uk-flex-center uk-flex-middle">
     <div class="uk-text-center uk-contrast">
      <?php if ( $title = beans_get_post_meta( 'beans_child_hero_title' ) ) : ?>
        <h1><?php echo esc_html( $title ); ?></h1>
      <?php endif; ?>
     <?php if ( $button_text = beans_get_post_meta( 'beans_child_hero_button_text' ) ) : ?>
        <p><a class="uk-button uk-button-primary uk-button-large" href="<?php echo esc_url( beans_get_post_meta( 'beans_child_hero_button_href' ) ); ?>" title="<?php echo esc_attr( $button_text ); ?>"><?php echo esc_attr( $button_text ); ?></a></p>
      <?php endif; ?>
     </div>
    </div>
  </div>
  <?php

}

I looked at your staging site, it is starting to look very good.

I"m have a hard time replicating the issue. The sample code is working on my side. Are you still having this issue?


Also fyi if you want to debug this issue send me a private message in the slack and I'll try to help you out.


Will try and join the slack, filled in my email but nothing coming through..

Could it be my version of wordpress? (5.2.3) or some write permission issue? Not sure how the input gets saved in the back-end. It should just save along with other page content once i hit 'update' right?

All the 'hero content' fields display, but after 'updating', closing the page, and jumping back in anything i put in them has all disappeared.

I'll see if i can get onto the Beans Slack channel. Cheers

Write a reply

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