Viewing 15 reply threads
  • Author
    Posts
    • #2483
      mcmaster
      Member

      I 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

    • #2486
      gabzon
      Member

      Interesting 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_categories

      piklist(‘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

    • #4962
      mcmaster
      Member

      *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

    • #4963
      Steve
      Keymaster

      @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_part or piklist_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.x
      

      The 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.

    • #4964
      mcmaster
      Member

      Yes, 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/.

    • #4965
      Steve
      Keymaster

      Yup! A Workflow is also a part.

    • #4999
      mcmaster
      Member

      Okay, 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!
      Donna

      p.s. the good news is that I am becoming ever more familiar with the innards of Piklist. 😉

    • #5010
      Steve
      Keymaster

      Did you try this filter: piklist_add_part ?

    • #5016
      mcmaster
      Member

      If 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_data array is always empty.

    • #5027
      Steve
      Keymaster

      @mcmaster– This code is in your main plugin file or functions.php? Not in the piklist/parts/ folder, correct?

    • #5030
      mcmaster
      Member

      @Steve: yes, I have a plugin mcw-piklist-custom with 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.php

      Donna

    • #5031
      mcmaster
      Member

      @sbruner, let me know if you’d like me to send you a zipped copy of the plugin

    • #5038
      Steve
      Keymaster

      @mcmaster– Yes, please send.

    • #6794
      mcmaster
      Member

      Follow-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.

    • #7509
      dameer
      Member

      It’s kinda late to participate here because with Piklist 0.9.9.9 neither of these functions (and filters) exist:
      piklist_get_file_data and piklist_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_data and piklist_part_add

      The 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!

    • #7520
      Jason
      Keymaster

      @dameer:

      Please 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! 🙂

Viewing 15 reply threads
  • You must be logged in to reply to this topic.