Created
June 6, 2016 21:01
-
-
Save jimi008/904938c68ee4f77dc231f0b617aacc6c to your computer and use it in GitHub Desktop.
Get Advance Custom Fields Value from Taxonomy Term
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! function_exists('custom_post_type') ) { | |
// Register Custom Post Type | |
function custom_post_type() { | |
$labels = array( | |
'name' => _x( 'Cars', 'Post Type General Name', 'text_domain' ), | |
'singular_name' => _x( 'Car', 'Post Type Singular Name', 'text_domain' ), | |
'menu_name' => __( 'Cars', 'text_domain' ), | |
'parent_item_colon' => __( 'Parent Car:', 'text_domain' ), | |
'all_items' => __( 'All Cars', 'text_domain' ), | |
'view_item' => __( 'View Car', 'text_domain' ), | |
'add_new_item' => __( 'Add New Car', 'text_domain' ), | |
'add_new' => __( 'Add New', 'text_domain' ), | |
'edit_item' => __( 'Edit Car', 'text_domain' ), | |
'update_item' => __( 'Update Car', 'text_domain' ), | |
'search_items' => __( 'Search Car', 'text_domain' ), | |
'not_found' => __( 'Not found', 'text_domain' ), | |
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ), | |
); | |
$args = array( | |
'label' => __( 'cars', 'text_domain' ), | |
'description' => __( 'custom post type for cars', 'text_domain' ), | |
'labels' => $labels, | |
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', 'post-formats', ), | |
'taxonomies' => array( 'models' ), | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'show_in_nav_menus' => true, | |
'show_in_admin_bar' => true, | |
'menu_position' => 5, | |
'can_export' => true, | |
'has_archive' => true, | |
'exclude_from_search' => false, | |
'publicly_queryable' => true, | |
'capability_type' => 'page', | |
); | |
register_post_type( 'cars', $args ); | |
} | |
// Hook into the 'init' action | |
add_action( 'init', 'custom_post_type', 0 ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! function_exists( 'custom_taxonomy' ) ) { | |
// Register Custom Taxonomy | |
function custom_taxonomy() { | |
$labels = array( | |
'name' => _x( 'Models', 'Taxonomy General Name', 'text_domain' ), | |
'singular_name' => _x( 'Model', 'Taxonomy Singular Name', 'text_domain' ), | |
'menu_name' => __( 'Models', 'text_domain' ), | |
'all_items' => __( 'All Models', 'text_domain' ), | |
'parent_item' => __( 'Parent Model', 'text_domain' ), | |
'parent_item_colon' => __( 'Parent Model:', 'text_domain' ), | |
'new_item_name' => __( 'New Model Name', 'text_domain' ), | |
'add_new_item' => __( 'Add New Model', 'text_domain' ), | |
'edit_item' => __( 'Edit Model', 'text_domain' ), | |
'update_item' => __( 'Update Model', 'text_domain' ), | |
'separate_items_with_commas' => __( 'Separate Models with commas', 'text_domain' ), | |
'search_items' => __( 'Search Models', 'text_domain' ), | |
'add_or_remove_items' => __( 'Add or remove Models', 'text_domain' ), | |
'choose_from_most_used' => __( 'Choose from the most used Models', 'text_domain' ), | |
'not_found' => __( 'Not Found', 'text_domain' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
); | |
register_taxonomy( 'models', array( 'cars' ), $args ); | |
} | |
// Hook into the 'init' action | |
add_action( 'init', 'custom_taxonomy', 0 ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php the_field('field_name', '{$term->taxonomy}_{$term->term_id}'); | |
// let assume the ID of Taxonomy term Audi is 4 | |
the_field( 'model_year', 'models_4' ); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$variable = get_field('field_name', 'product-cat_23'); | |
// do something with $variable | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment