meta-box icon indicating copy to clipboard operation
meta-box copied to clipboard

meta data issue

Open atashinbar opened this issue 9 years ago • 5 comments

With your plugin, we have created some options for our pages to let user on/off header or footer but when we import WordPress own dummy into https://wpcomthemes.svn.automattic.com/demo/theme-unit-test-data.xml footer and header option stays on “off” by default and it does not load unless we click on “update” button in edit page. Although when we manually make it “on” and then click on “update” button it works. The another issue that we’d like to share is that in some pages such as buddypress “group” this settings do not work at all, header and footer stay “off”. How is possible to change default settings? Or is there other ways to get a better result by this plugin?

atashinbar avatar May 29 '16 06:05 atashinbar

Hi, can you please post the code you used to register meta box and fields?

rilwis avatar May 31 '16 17:05 rilwis

Hi there, It is my backend code: add_filter( 'rwmb_meta_boxes', 'test_meta_boxes' ); function test_meta_boxes( $meta_boxes ) { $meta_boxes[] = array( 'title' => esc_attr__( 'test Page Options', 'test' ), 'post_types' => 'page', 'fields' => array( array( 'id' => 'test_topbar_show', 'name' => esc_attr__( 'Show Topbar', 'test' ), 'type' => 'checkbox', 'std' => 1, ), array( 'id' => 'test_header_show', 'name' => esc_attr__( 'Show Header', 'test' ), 'type' => 'checkbox', 'std' => 1, ), array( 'id' => 'test_footer_show', 'name' => esc_attr__( 'Show Footer', 'test' ), 'type' => 'checkbox', 'std' => 1, ), ), ); return $meta_boxes; }

And it is footer.php code for example : $footer_show = true; if(isset($post)){ $footer_show = rwmb_meta( 'test_footer_show' ); } if ( $footer_show || is_archive() || is_single() || is_home() ) { }

atashinbar avatar Jun 01 '16 07:06 atashinbar

I've just tested the code and I see the backend works correctly. That means the value is saved correctly.

In the frontend: please make sure that you don't change the global object $post, because the function rwmb_meta get the post meta from the current post in the loop. So if you modified the query, you should reset it using wp_reset_postdata.

PS: I see you use $post object directly. It might be the problem.

rilwis avatar Jun 02 '16 03:06 rilwis

To clarify the situation I’ve prepared a file and put “functions.php” and “header.php” inside of it. After installing 2016 theme and putting attached files instead of related theme files on a fresh WordPress, if you review “sample.php” page it comes without header but if you enter to page edit and click on update the header appears. functions.txt header.txt

atashinbar avatar Jun 06 '16 05:06 atashinbar

Hi there, Do you have any Idea about that?

atashinbar avatar Jul 16 '16 05:07 atashinbar