Support

Account

Forum Replies Created

  • Not sure if this has already been discussed, but I actually accomplished this natively using two separate field groups. The first field group applies to my CPT and is a Taxonomy checkbox. Then, I make the field in my second field group required, but I set the LOCATION RULE to only display if my CPT belongs to a specific term (using Post Taxonomy in Location Rule). Seems to work quite well, the only downside is having to deal with two field groups, but it’s a minor organizational inconvenience.

  • This one is a bit old but I just came across the need to do this. I don’t exclude videos, but I like to exclude PNGs and TIFFs on Image fields because their file sizes can be wildly large. Here’s how I do it:

    
    function prevent_certain_image_uploads($errors, $file, $attachment, $field, $context) {
    	$disallowed_formats = array('png', 'tiff');
    	if(in_array(strtolower($file['type']), $disallowed_formats)) {
    		$errors['mime_types'] = sprintf(__('File type may not be %s.', 'acf'), strtoupper($file['type']));
    	}
    	return $errors;
    }
    add_filter('acf/validate_attachment/type=image', __NAMESPACE__.'\\prevent_certain_image_uploads', 10, 5);
    

    It’s pretty easy to adapt this to your use case, just add the file extensions you want to exclude to the $disallowed_formats array and you should be good to go!

  • I compromised the feature that this logic was part of. If you figure out a way to get this working smoothly though please let us know!

  • Just want to go on record and point out that I experienced the same issue. All three filters:

    acf/fields/taxonomy/query
    acf/fields/taxonomy/query/name=
    acf/fields/taxonomy/query/key=

    fail to actually filter the taxonomy field query. This was tested in a functions.php file with plenty of other valid, working ACF customizations.

  • I’m a little late to this party but I was at my wits’ end figuring this out and managed to nail it.

    I have a custom taxonomy called issue which has a custom field issue_date (date picker field). I wanted to add a custom column in the taxonomy edit screen to sort my issues by their dates. Here is what I came up with:

    Step 1: Add the new Date column

    function issue_columns($issue_columns) {
      $issue_columns['date'] = 'Date';
      return $issue_columns;
    }
    add_filter('manage_edit-issue_columns', 'issue_columns');

    Step 2: Populate the new Date column

    function manage_issue_columns($out, $column_name, $term_id) {
      $issue = get_term($term_id, 'issue');
      $date = DateTime::createFromFormat('Ymd', get_field('issue_date', $issue));
      switch($column_name) {
        case 'date': 
          $out = $date->format('Y/m/d');
        break;
        default:
        break;
      }
      return $out;    
    }
    add_filter('manage_issue_custom_column', 'manage_issue_columns', 10, 3);

    Step 3: Make the new Date column sortable

    function my_sortable_issue_column($columns) {
      $columns['date'] = 'issue_date';
      return $columns;
    }
    add_filter('manage_edit-issue_sortable_columns', 'my_sortable_issue_column');

    Step 4: Define the custom sorting (where the magic happens)

    function sort_issues_by_date_column($pieces, $tax, $args) {
      global $pagenow;
      if(!is_admin()) {
        return;
      }
    
      if(is_admin() && $pagenow == 'edit-tags.php' && $tax[0] == 'issue' && (!isset($_GET['orderby']) || $_GET['orderby'] == 'issue_date')) {
        $pieces['join']   .= " INNER JOIN wp_options AS opt ON opt.option_name = concat('issue_',t.term_id,'_issue_date')";
        $pieces['orderby'] = "ORDER BY opt.option_value";
        $pieces['order']   = isset($_GET['order']) ? $_GET['order'] : "DESC";
      }
    
      return $pieces;
    }
    add_filter('terms_clauses', 'sort_issues_by_date_column', 10, 3);

    For reference, my date picker field setting returns the date in the format Ymd.

    If anyone has any improvements or questions please let me know!

  • I decided to give this a shot and also decided it would be best to allow for configuring the Featured post from within the post itself or from my site’s home page (i.e., front page). I also wanted to ensure this would work for scheduled posts. I’d love feedback on more effective methods or if any of this code can be tightened up at all.

    My custom post type is article and I setup two fields: a checkbox within each article and a Post Object field on the home page, both fields called featured_article. Here’s how I did it:

    
    function allow_only_one_featured_article($post_id, $post) {
      if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
      }
    
      $homepage = get_option('page_on_front');
    
      if($homepage == $post_id && get_post_status(get_post_meta($post_id, 'featured_article', true)) == 'publish') {
        // only fires during save_post hook if Home was just saved AND the chosen Article is published
    
        $exclude = get_post_meta($post_id, 'featured_article', true);  // save the Article ID to exclude from the query (below) that removes Featured status from other Articles
        update_post_meta($exclude, 'featured_article', 1);             // check the Featured Article's checkbox
    
      } elseif(get_post_type($post_id) == 'article' && (get_post_meta($post_id, 'featured_article', true) == 1 || get_post_meta($homepage, 'featured_article', true) == $post_id)) {
        // if an Article has either its Featured checkbox is checked, or it's selected on Home
    
        $exclude = $post_id;                                           // save the Article ID to exclude from the query (below) that removes Featured status from other Articles
        update_post_meta($exclude, 'featured_article', 1);             // check Article's checkbox (in case scheduled Article is set from Home)
        update_post_meta($homepage, 'featured_article', $post_id);     // update Home selection
    
        if($post->post_status != 'publish') {                          // don't remove Featured status from other Articles unless the Article is published
          return;
        }
    
      } else {
        return;
      }
    
      // Unset all Featured Articles except the current one that's being saved or published
      $featured_articles = new WP_Query(array(
        'post_type'    => 'article',
        'post__not_in' => array($exclude),
        'meta_query'   => array(array(
          'key'        => 'featured_article',
          'value'      => 1,
          'compare'    => '='
        )),
        'fields'       => 'ids'
      ));
      $featured_article_ids = $featured_articles->posts;
    
      foreach($featured_article_ids as $f) {
        update_post_meta($f, 'featured_article', 0);
      }
    
    }
    add_action('save_post', 'allow_only_one_featured_article', 10, 2);
    add_action('publish_article', 'allow_only_one_featured_article', 10, 2);
    
  • Just to let everyone know, I’ve been in touch with Elliot on this. A fix has been implemented and an update will be forthcoming shortly!

  • I’m actually still experiencing this issue on a MacBook Pro, but I do click my trackpad instead of tapping it. No console errors whatsoever, just an unresponsive Flexible Content button. I don’t even see the fields if I set the minimum to 1.

    This is all taking place within an Options page and it also happens on posts. I don’t have any other plugins installed and the only customization I’ve made is to register a custom taxonomy. For reference, I’m using the Roots theme (http://roots.io) but I experience the same issues with Twenty Fourteen.

    Using ACF PRO 5.0.8.

    Any help would be much appreciated.

  • Hi Elliot and ACF devs,

    I recently made the switch to ACF Pro and it’s great, I’m finding it much faster to work with and streamlining all addons into one plugin was a great step forward.

    I was wondering if there is any update on a Composer package?

    Thanks!

  • This is a defect/bug in WP which will be fixed with the release of WP 4.0.

    In the meantime, instead of using replacement functions you can use the filter I posted here: http://stackoverflow.com/a/24686483/1231001

Viewing 10 posts - 1 through 10 (of 10 total)