Tagged: conditions, meta-box, term
- This topic has 15 replies, 5 voices, and was last updated 5 years, 3 months ago by
Jason.
-
AuthorPosts
-
-
September 25, 2014 at 12:24 am #2483
mcmasterMemberI want to show certain metaboxes only if a post is in a certain category. I see the info on setting a condition based on a different field but not on taxonomy. Is this supported?
Thanks!
Donna -
September 26, 2014 at 4:28 am #2486
gabzonMemberInteresting question. I really have no idea, try maybe something like:
1. Get the list of categories
2 Use piklist condition and add your list of categories in a select or checkbox field
3. Then use the value field to compare it with the value selected in the list.ex:
$list = your_categoriespiklist(‘field’, array(
‘type’ => ‘select’
,’field’ => ‘my_categories’
,’label’ => ‘Would you like to subscribe to our newsletter?’
,’attributes’ => array(
‘class’ => ‘text’
)
,’choices’ => $list /*Look at the format*/
));piklist(‘field’, array(
‘type’ => ‘text’
,’field’ => ’email_address’
,’label’ => ‘Email Address’
,’description’ => ‘Please enter your email address’
,’conditions’ => array(
array(
‘field’ => ‘my_categories’
,’value’ => ‘the_conditional_category’
)
)
));Anyways, try something like this
Good Luck -
November 14, 2015 at 9:45 pm #4962
mcmasterMember*bump*
I’m converting a client’s site from ACF to Piklist, and ran into this again. She has a post category for Podcasts, and we have an ACF field group for credits that is only applicable to these posts.
@gabzon’s suggestion works if you want to show only certain fields in a meta-box, but for non-podcast posts we don’t need any meta-box at all.I saw that meta-boxes shown only for certain post formats is in the works, so I’m crossing my fingers that this might also be in the works? https://piklist.com/support/topic/metabox-based-on-post-format-type/
Thanks!
Donna -
November 14, 2015 at 10:16 pm #4963
SteveKeymaster@mcmaster– We probably won’t add hide/show by taxonomy term to Piklist. There are just too many variations on what a developer might want to hide/show a metabox or field. So instead we added filters so you can do whatever you want.
Here are two suggestions:
1) Hide the field, leave the meta-box: Just wrap the field in a simple php conditional.
2) Hide the meta-box: You are going to have to use a Piklist filter. Either
piklist_add_partorpiklist_part_add, depending on which version of Piklist you are running. We renamed it in v9.5. Fortunately, you can actually use both so you can be backwards/forwards compatible.We used this filter in WP Helpers, when you want to make the excerpt box a wysiwyg so you can use that as a resource:
-Open wp-helpers.php and look for these lines:add_filter('piklist_add_part', array('piklist_wordpress_helpers', 'replace_post_excerpt_box'), self::$filter_priority, 2); // Piklist v0.9.4.x add_filter('piklist_part_add', array('piklist_wordpress_helpers', 'replace_post_excerpt_box'), self::$filter_priority, 2); // Piklist v0.9.5.xThe function
replace_post_excerpt_box()looks for a meta-box with a fake post_type of piklist_wp_helpers_post. We set it to this post_type so it doesn’t display by default. You can use your condition to just change the post_type to post:$part_data['type'] = 'post';
Take a look and let me know if it makes sense.
-
November 14, 2015 at 11:35 pm #4964
mcmasterMemberYes, that makes sense. Thanks, Steve.
Would that approach also work for limiting a workflow to one page ID? See https://piklist.com/support/topic/limiting-workflow-to-specific-post-id-or-template/.
-
November 14, 2015 at 11:47 pm #4965
SteveKeymasterYup! A Workflow is also a part.
-
November 16, 2015 at 9:50 pm #4999
mcmasterMemberOkay, I’m probably doing something hopelessly dumb, but I can’t seem to get this to work. I set up the filter and function based on the wp-helpers excerpt example:
add_filter( 'piklist_part_add', 'mcw_check_categories', 9999, 2 ); function mcw_check_categories ( $part_data, $folder ) { if ( empty( $part_data ) ) { return $part_data; } // get post ID to test against category terms if ( isset( $_REQUEST['post'] ) ) { $post_id = $_REQUEST['post']; } elseif ( isset( $_REQUEST['post_ID'] ) ) { $post_id = $_REQUEST['post_ID']; } else { return $part_data; } if ( in_category( array( 'podcasts', 'music-service-videos' ), $post_id ) ) { if ( $folder == 'meta-boxes' ) { if ( !empty( $part_data['type'] ) && $part_data['type'] == 'post_credits' ) { $part_data['type'] = 'post'; } } } return $part_data; }It did nothing. I put in some error logging to figure out where it was breaking, and $part_data is always an empty array. I set the filter priority to 9999, which is the same as in wp-helpers.
Any suggestions?
Thanks so much!
Donnap.s. the good news is that I am becoming ever more familiar with the innards of Piklist. 😉
-
November 17, 2015 at 11:12 am #5010
SteveKeymasterDid you try this filter:
piklist_add_part? -
November 17, 2015 at 4:16 pm #5016
mcmasterMemberIf I filter on
piklist_add_part, my function is never called.When I filter on
piklist_part_add, the function is called but the$part_dataarray is always empty. -
November 18, 2015 at 11:21 am #5027
-
November 18, 2015 at 5:37 pm #5030
mcmasterMember@Steve: yes, I have a plugin
mcw-piklist-customwith several add-ons that I enable the same way that Piklist Demos is enabled. This is in the main file for one of the add-ons:plugins/mcw-piklist-custom/add-ons/mcw-post-custom/mcw-post-custom.phpDonna
-
November 18, 2015 at 5:40 pm #5031
-
November 19, 2015 at 12:30 pm #5038
-
June 23, 2016 at 7:41 pm #6794
mcmasterMemberFollow-up for anyone else interested in this feature: I got a private email back in November saying that this would be fixed in the next release, but didn’t update the thread.
-
November 10, 2016 at 6:22 am #7509
dameerMemberIt’s kinda late to participate here because with Piklist 0.9.9.9 neither of these functions (and filters) exist:
piklist_get_file_dataandpiklist_add_part
…even though the docs and tutorial (https://piklist.com/learn/doc/hide-meta-boxes-page-template/) relies on it.It’s been a while since Piklist last update and I wonder whether it means the end of this fabulous framework?
Currently I’m sharing the issue with @mcmaster and need to find a proper way to hide metabox for certain (custom) page template. It looks like mission impossible.
By digging into Piklist core files I found 2 filters that kinda make sense:
piklist_part_dataandpiklist_part_addThe first one allows me to append custom data to data array while the second one grabs empty array.
Is there any other filter or method to check for the template being used in the back-end and then conditionally show/hide metabox?
Thanks!
-
November 11, 2016 at 1:23 pm #7520
JasonKeymasterPlease see this concerning Piklist notbeing dead: https://piklist.com/support/topic/is-it-true-that-piklist-is-dead/
Otherwise, the documentation has definitely been strained. I’ll agree to that. You’re right that some of the filters don’t exist anymore, as at 0.9.9.9 there were some significant internal changes that greatly simplified and improved how parts (i.e. metaboxes, settings, etc.) are processed within Piklist. Consequently some of the filters were consolidated.
I believe
piklist_part_process(first parameter is $part, second is $folder) may be the filter you’re looking for to finish off your list. Since you’re in the code, look at the piklist::process_parts function. That’s how all parts within Piklist are processed and subsequently displayed. If you return null/false in that filter then the part is not displayed.Hope this helps! 🙂
-
-
AuthorPosts
- You must be logged in to reply to this topic.