Tagged: conditional, metabox, solution
- This topic has 5 replies, 2 voices, and was last updated 6 years, 1 month ago by
mcmaster.
-
AuthorPosts
-
-
May 2, 2015 at 12:53 am #3669
mcmasterMemberI have a “section_name” field that I want to show only for top-level pages. Was first looking at using a template but then I saw the tutorial https://piklist.com/user-guide/tutorials/hide-meta-boxes-page-template/ and modified it for my use. I’m sharing the code in case someone else might find it handy. Suggestions for improvement are also welcome. 🙂
-
May 2, 2015 at 4:58 pm #3670
mcmasterMemberHeads up … I’m using the Beta version of Piklist. In the current Piklist 0.9.4.24 release, the piklist_get_file_data filter passes only one parameter, the $data array. This leads to an error message for the missing $type parameter.
In the Beta version, the $type parameter is there.
Donna
-
December 23, 2015 at 7:55 am #5419
abmcrMemberIn the last 0.9.9.6 the
piklist_get_file_data filter don’t exist?
I have try to use the codeadd_filter('piklist_get_file_data', 'my_custom_comment_block', 10, 2); function my_custom_comment_block($data, $type) { // If not a Meta-box section than bail if($type != 'meta-boxes') { return $data; } // Allow Piklist to read our custom comment block attribute: "Hide for Template", and set it to hide_for_template $data['hide_for_template'] = 'Hide for Template'; return $data; } add_filter('piklist_add_part', 'my_hide_for_template', 10, 2); function my_hide_for_template($data, $type) { global $post; // If not a meta box than bail if($type != 'meta-boxes') { return $data; } // Check if any page template is set in the comment block if (!empty($data['hide_for_template'])) { // Get the active page template $active_template = pathinfo(get_page_template_slug($post->ID), PATHINFO_FILENAME); //valuta se pagina è front page if($post->ID !== get_option( 'show_on_front' ) ){ // Change meta-box access to user role: no-role $data['role'] = 'no-role'; } } return $data; }And it not work; i have serached the filter and i have not found it
-
December 23, 2015 at 8:01 am #5420
mcmasterMemberThe beta I was using back then was 0.9.5.x, so it could have changed. The Gist URL has changed, BTW, it is now https://gist.github.com/donnamcmaster/7324cba06b375ef35b5b.
-
December 23, 2015 at 10:15 am #5421
abmcrMemberYes: i confirm
In the new 0.9.9.6 the code you post and my also are not working
The filter don’t exist -
December 25, 2015 at 12:14 am #5423
mcmasterMemberYes, it’s clear that tutorial at https://piklist.com/user-guide/tutorials/hide-meta-boxes-page-template/ needs updating. Neither piklist_get_file_data nor piklist_add_part filters are executed in 0.9.9.x.
I think they may be replaced with piklist_part_data along with some of the variants in Piklist::process_parts, and also piklist_part_data_parameter? (See file plugins/piklist/includes/class-piklist.php.)
No time to test right now, but let us know if you find the magic formula. 😉
Cheers,
Donna
-
-
AuthorPosts
- You must be logged in to reply to this topic.