SOLFIND
Web Lens
Portal home

hero content (post meta) not saving? | Discussion | Beans WordPress Theme Framework

https://community.getbeans.io/discussion/hero-content-post-meta-not-saving/ • 31 KB fetched
Open original page


hero content (post meta) not saving? | Discussion | Beans WordPress Theme Framework

* Skip to the content.

* Skip to the primary sidebar.

Menu
* Themes

* Showcase

* Docs

* Support

* Community

*

* Forums

* Support

* hero content (post meta) not saving?

hero content (post meta) not saving?

Maurice Tadros

*

*

*

Posted 6 years, 12 months ago

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

Niels Hunefeld

*

*

*

Posted 6 years, 12 months ago

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

}

Maurice Tadros

*

*

*

Posted 6 years, 11 months ago

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?

Maurice Tadros

*

*

*

Posted 6 years, 11 months ago

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.

Niels Hunefeld

*

*

*

Posted 6 years, 11 months ago

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!

* Login

* Register

Start a discussion

*
Your Profile

*
Login

*
All Discussions

*
Join Beans Slack Team

Search a discussion

Search for:

Forums

*
General

*
Support

*
Extend

“Beans Theme Framework, be a part of something awesome!”

© Beans | Contact | Donate Founded by Thierry Muller , co-maintained by Tonya Mork

Beans project is no longer maintained, thanks for your support for so many years. Stay awesome!

Links found on this page

  1. Skip to the content. [direct]
  2. Themes [direct]
  3. Showcase [direct]
  4. Docs [direct]
  5. Support [direct]
  6. Community [direct]
  7. Forums [direct]
  8. Support [direct]
  9. Maurice Tadros [direct]
  10. Niels Hunefeld [direct]
  11. http://dev-staging.herbscience.co.nz/ [direct]
  12. Login [direct]
  13. Register [direct]
  14. Start a discussion [direct]
  15. Your Profile [direct]
  16. Join Beans Slack Team [direct]
  17. General [direct]
  18. Extend [direct]
  19. Contact [direct]
  20. Donate [direct]
  21. Thierry Muller [direct]
  22. Tonya Mork [direct]