name = 'url_object'; $this->label = __( "URL Object", 'acf-url' ); $this->category = __( "Choice", 'acf' ); parent::__construct(); } /*-------------------------------------------------------------------------------------- * * create_field * * *-------------------------------------------------------------------------------------*/ function create_field( $field ) { // vars $args = array( 'numberposts' => -1, 'post_type' => null, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => array( 'publish', 'private', 'draft', 'inherit', 'future' ), 'suppress_filters' => false, ); $defaults = array( 'multiple' => 0, 'post_type' => false, 'taxonomy' => false, 'allow_null' => 0, ); $field = array_merge( $defaults, $field ); // validate taxonomy if( ! is_array( $field['taxonomy'] ) ) { $field['taxonomy'] = false; } if( is_array( $field['taxonomy'] ) && in_array( 'none', $field['taxonomy'] ) ) { $field['taxonomy'] = false; } // load all post types by default if( ! $field['post_type'] || ! is_array( $field['post_type'] ) || $field['post_type'][0] == "" ) { $field['post_type'] = apply_filters( 'acf/get_post_types', array() ); } // Change Field into a select $field['type'] = 'select'; $field['choices'] = array(); $field['optgroup'] = false; foreach( $field['post_type'] as $post_type ) { // set post_type $args['post_type'] = $post_type; // set order if( is_post_type_hierarchical( $post_type ) && ! isset( $args['tax_query'] ) ) { $args['sort_column'] = 'menu_order, post_title'; $args['sort_order'] = 'ASC'; $posts = get_pages( $args ); } else { $posts = get_posts( $args ); } if( $posts ) { foreach( $posts as $post ) { // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory $title = ''; $ancestors = get_ancestors( $post->ID, $post->post_type ); if( $ancestors ) { foreach( $ancestors as $a ) { $title .= '–'; } } $title .= ' ' . apply_filters( 'the_title', $post->post_title, $post->ID ); // status if( $post->post_status != "publish" ) { $title .= " ($post->post_status)"; } // WPML if( defined('ICL_LANGUAGE_CODE') ) { $title .= ' (' . ICL_LANGUAGE_CODE . ')'; } // add to choices if( count( $field['post_type'] ) == 1 && $field['taxonomy'] == false ) { $field['choices'][ 'post-' . $post->post_type . '-' . $post->ID ] = $title; } else { // group by post type $post_type_object = get_post_type_object( $post->post_type ); $post_type_name = $post_type_object->labels->name; $field['choices'][$post_type_name][ 'post-' . $post->post_type . '-' . $post->ID] = $title; $field['optgroup'] = true; } } // foreach( $posts as $post ) } // if($posts) } //add tax link foreach( $field['taxonomy'] as $taxonomy ) { if ( taxonomy_exists( $taxonomy ) ){ $tax_object = get_taxonomy( $taxonomy ); $tax_name = $tax_object->labels->name; $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id')); foreach ( $terms as $term ){ $field['choices'][$tax_name]['tax-' . $taxonomy . '-' . $term->term_id] = $term->name; } } } // foreach( $field['post_type'] as $post_type ) //wp_enqueue_script('acf_url_field',plugin_dir_url(__FILE__).'js/acf_url.js'); if( is_array( $field['value'] ) && isset( $field['value']['link'] ) ) { $value = $field['value']['link']; $label = $field['value']['label']; $field['value'] = $value; } else { $value = $field['value']; $label = ""; } $internal= ( preg_match( '!^(post|tax)-(.*?)-([0-9]+)$!', $field['value'] ) && strpos( $field['value'], "http" ) == false ); ?>
| $fieldname ) { if ( strpos( $fieldname, 'field_' ) ) { $fieldname = trim( $fieldname, '[]' ); $fieldinfo = $this->get_acf_field( $fieldname ); if ( $fieldinfo && isset( $fieldinfo['name'] ) ) { $hierarchy_field[] = $fieldname; $newfieldname .= $glue . $fieldinfo['name']; } elseif ( ! empty( $hierarchy_field ) ) { $parentname = end( $hierarchy_field ); $currentfieldinfo = $this->get_acf_field( $parentname ); $name = $currentfieldinfo['sub_fields'][$fieldname]['name']; $newfieldname .= $glue.$name; } $glue = "_"; } else { $fieldname = trim( $fieldname, '[]' ); $newfieldname .= $glue . $fieldname; $glue = "_"; } } ?> | |
|
|