Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta data issue #883

Open
atashinbar opened this issue May 29, 2016 · 5 comments
Open

meta data issue #883

atashinbar opened this issue May 29, 2016 · 5 comments
Labels

Comments

@atashinbar
Copy link

atashinbar commented May 29, 2016

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?

@rilwis
Copy link
Member

rilwis commented May 31, 2016

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

@atashinbar
Copy link
Author

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() ) { }

@rilwis
Copy link
Member

rilwis commented Jun 2, 2016

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 rilwis added the review label Jun 2, 2016
@atashinbar
Copy link
Author

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
Copy link
Author

Hi there,
Do you have any Idea about that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants