Home Page Include
Support › MB Include Exclude › Home Page Include
- This topic has 1 reply, 2 voices, and was last updated 6 years, 11 months ago by
Anh Tran.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
May 27, 2018 at 11:58 AM #9763
carassius
ParticipantI am trying to use include/exclude on my home page only but it doesnt want to play ball.
If i remove the incude array, everything works across all pages, so I know it is my custom function not working.
Any thoughts on where I am going wrong?
This is my function for the custom call
public function evis_include_home( $meta_box ) { $front_page = (int)get_option( 'page_on_front' ); global $post; $id = $post->ID; if ( $id == $front_page ) return true; return false; }
And this is my include array
'include' => array ( 'relation' => 'AND', 'custom' => 'evisMetaboxes::evis_include_home', ),
The entire class looks like this
<?php class evisMetaboxes { function evis_register_home_hero_meta_boxes( $meta_boxes ) { $meta_boxes[] = array ( 'title' => 'Home Page Hero', 'post_types' => array ( 'page', ), 'context' => 'normal', 'priority' => 'high', 'status' => 'publish', 'autosave' => false, 'fields' => array ( array ( 'id' => 'home_hero_title', 'type' => 'text', 'name' => 'Hero Title', 'std' => 'Evis Resort.', ), array ( 'id' => 'home_hero_tagline', 'type' => 'textarea', 'name' => 'Hero Tagline', ), array ( 'id' => 'home_hero_button', 'type' => 'group', 'name' => 'Hero Button', 'fields' => array ( array ( 'id' => 'hero_button_text', 'type' => 'text', 'name' => 'Text', 'std' => 'Explore Evis Resort', ), array ( 'id' => 'home_button_link', 'type' => 'text', 'name' => 'Link', ), ), 'default_state' => 'expanded', 'groupfield' => 'text', ), ), 'id' => 'home-page-hero', 'include' => array ( 'relation' => 'AND', 'custom' => 'evisMetaboxes::evis_include_home', ), ); return $meta_boxes; } public function evis_include_home( $meta_box ) { $front_page = (int)get_option( 'page_on_front' ); global $post; $id = $post->ID; if ( $id == $front_page ) return true; return false; } }
May 28, 2018 at 3:02 PM #9803Anh Tran
KeymasterI think the way you access to
global $post
is incorrect. That global object is not available when registering meta box. To get the post ID, please use this code instead:https://github.com/wpmetabox/library/blob/master/conditional-display/better-include.php#L66
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- The topic ‘Home Page Include’ is closed to new replies.