Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

reply

  • Hi @jordan314

    I have not yet tested ACF with the user taxonomy plugins so I can’t guarantee this would work.

    Are you able to use the WP interface for this instead of ACF for now?

  • Hi @Debatewise

    I think we need to go back to the start of this project and learn to crawl before you try to run.

    Can you please re-explain the issue without refering to any code or work you had previously done. Lets start fresh so I can understand the issue.

    * You have a CPT called ‘Promo Boxes’
    * ‘Promo Boxes’ suports the ‘category’ taxonomy
    * Promo Boxes has some custom fields. What are they? Are they relevant to this issue?
    * You are tyring to load the category ID. Where from. What URL are you looking at? What template file is running?

    Thanks
    E

  • Hi @trasyhoob

    Just to clarify, are you saying:

    You have a front end form for editing a post. When you select a taxonomy value for this post, you would like ACF to load in any new field groups which now match (like in the wp-admin)?

  • Hi Elliot,

    1. You are setting the variable $post_objects twice. Why?
    Most probably because I don’t know what I’m doing :). I’ve removed the extraneous one on my code now.

    2. I can’t see in your code where you are loading the category for.
    I think this is my problem, I’m not sure how to load the category. What I’ve done is:

    1. Created a custom field type (Promo Boxes) – which includes the categories built-in taxonomy
    2. Created custom fields and tied them to the Promo Boxes CPT
    3. Created a post in Promo Boxes and assigned it to a category
    4. Tried to grab the category ID from this particular post

    Does that make sense?

    There is no custom field containing the category name, should there be?

  • Hello, I have a number of taxonomies, frond end ACF form and html-select of this taxonomies. I want to load group of fields which match selected taxonomy dynamically… (via ajax)… how i can do this…?

  • Thanks Elliot,

    I’ll see if I can put together a new field type, looks like it shouldn’t be too difficult to add a simplified version of wp’s term adding form to the taxonomy picker.

    Thanks for all your work on ACF, it’s an incredibly useful plugin!

    Tom

  • Hi @blackpenpress

    Yes, currently you will need to use WP to create a term. ACF taxonomy field is only to select them.

    Hopefully in the near future, we will see this feature added.

    Thanks
    Elliot

  • Hi @devinwalker

    Thanks for the great idea. I’ll add this to the to-do

  • That’s not a bad idea… I was hoping someone else had come across this before or had any code to start from. Otherwise, I may code it up in the next day or so if this thread gets buried.

  • Hey dude!

    I think that if you want to do this you’d have to go into the relationship field file and add the functionality. It shouldnt be too hard since Elliot has already added a filter by post type..

    If you want it to stay “clean” you can copy the field to your theme, rename it and do the changes there and thus creating a custom relationship field beside the regular one.

  • Hi @seamusleahy

    Thanks for the feedback. This will be added in a future update.

    Cheers
    Elliot

  • Let’s start by trying include the PayPal field last.

    
    
    // custom action for saving the front end form
    	function my_pre_save_post( $post_id )
    	{
    	    // check if this is to be a new post
    	    if( $post_id != 'new' )
    	    {
    	        return $post_id;
    	    }
    	 
    	    // Create a new post
    	    $post = array(
    	        'post_status'  => 'draft' ,
    	        'post_title'  => $_POST['title'],
    	        'tax_input'     => array('job-category' => $_POST['job-category']),
    	        'post_type'  => 'jobs_post' ,
    	    );  
    	 
    	    // insert the post
    	    $post_id = wp_insert_post( $post ); 
    	 
    	 	// now set the taxonomy
    	 	wp_set_object_terms($post_id, array($_POST['job-category']), 'job-category');
    //	 	wp_set_object_terms($post_id, array($_POST['salary-range']), 'salary-range');
    	 
    	    // return the new ID
    	    return $post_id;
    	}
    	add_filter('acf/pre_save_post' , 'my_pre_save_post' );
    	
    	//Rename Options Menu ACF	
    	function my_acf_options_page_settings( $settings )
    	{
    		$settings['title'] = 'Theme Options';
    		$settings['pages'] = array('Email', 'Google AdSense', 'Google Analytics', 'Logo', 'Theme Colors');
    	 
    		return $settings;
    	}
    	 
    	add_filter('acf/options_page/settings', 'my_acf_options_page_settings');	
    	//end
    
    	include_once('add-ons/advanced-custom-fields/acf.php');
    	include_once('add-ons/acf-location-field-master/acf-location.php');
    	include_once('add-ons/acf-repeater/acf-repeater.php');
    	include_once('add-ons/acf-options-page/acf-options-page.php');
    	include_once('add-ons/acf-taxonomy-field-master/taxonomy-field.php');
    
    	require ( get_template_directory() . '/add-ons/custom-widgets.php' );
    	require ( get_template_directory() . '/add-ons/custom-form.php' );
    
    //ACF PayPal 
    	add_action('acf/register_fields', 'my_register_fields');
    	
    	function my_register_fields()
    	{
    	    include_once('add-ons/acf-paypal-field-master/paypal_item-v4.php');
    	}
    
    
  • Thanks Mike, I appreciate it! Here is all the code in my functions.php relating to acf:

     
    // custom action for saving the front end form
    	function my_pre_save_post( $post_id )
    	{
    	    // check if this is to be a new post
    	    if( $post_id != 'new' )
    	    {
    	        return $post_id;
    	    }
    	 
    	    // Create a new post
    	    $post = array(
    	        'post_status'  => 'draft' ,
    	        'post_title'  => $_POST['title'],
    	        'tax_input'     => array('job-category' => $_POST['job-category']),
    	        'post_type'  => 'jobs_post' ,
    	    );  
    	 
    	    // insert the post
    	    $post_id = wp_insert_post( $post ); 
    	 
    	 	// now set the taxonomy
    	 	wp_set_object_terms($post_id, array($_POST['job-category']), 'job-category');
    //	 	wp_set_object_terms($post_id, array($_POST['salary-range']), 'salary-range');
    	 
    	    // return the new ID
    	    return $post_id;
    	}
    	add_filter('acf/pre_save_post' , 'my_pre_save_post' );
    	
    	//ACF PayPal 
    	add_action('acf/register_fields', 'my_register_fields');
    	
    	function my_register_fields()
    	{
    	    include_once('add-ons/acf-paypal-field-master/paypal_item-v4.php');
    	}
    	
    	//Rename Options Menu ACF	
    	function my_acf_options_page_settings( $settings )
    	{
    		$settings['title'] = 'Theme Options';
    		$settings['pages'] = array('Email', 'Google AdSense', 'Google Analytics', 'Logo', 'Theme Colors');
    	 
    		return $settings;
    	}
    	 
    	add_filter('acf/options_page/settings', 'my_acf_options_page_settings');	
    	//end
    
    	include_once('add-ons/advanced-custom-fields/acf.php');
    	include_once('add-ons/acf-location-field-master/acf-location.php');
    	include_once('add-ons/acf-repeater/acf-repeater.php');
    	include_once('add-ons/acf-options-page/acf-options-page.php');
    	include_once('add-ons/acf-taxonomy-field-master/taxonomy-field.php');
    
    	require ( get_template_directory() . '/add-ons/custom-widgets.php' );
    	require ( get_template_directory() . '/add-ons/custom-form.php' );
    
  • I am sending screens to assist in troubleshooting.
    thank you!




  • From documentation:

    All the API functions can be used with a taxonomy term, however, a second parameter is required to target the term ID. This is similar to passing through a post_id to target a specific post object.

    The $post_id needed is a string containing the taxonomy name + the term ID in this format: “$TaxonomyName_$TermID”
    Examples
    Display a field

    <p><?php the_field('field_name', 'thetaxonomyname_7'); ?></p>

  • By the way chaps thanks incredibly for the help, I was ready to gauge out my eyes. 🙂

    Mike J

  • No matter I fixed it. The problem was with “get_field” I replaced it with “the_field”

    
    <?php
     
    global $post;
     
    // load all 'category' terms for the post
     $terms = get_the_terms($post->ID, "product_brand");
     
    // we will use the first term to load ACF data from
    if( !empty($terms) )
    {
    	$term = array_pop($terms);
     
    	$custom_field = the_field('contact_info', 'product_brand_' . $term->term_id);
     
    	// do something with $custom_field
    }
     
    ?>
    
  • I’m afraid changing “category_” to “product_brand_” had no effect. It’s almost like that line has no way of getting the id of the current term. The address reads like this http://site/?product_brand=1st-call-mobility where “1st-call-mobility” is the term of the product_brand taxonomy.

    “contact_info” is my ACF field slug, and “Brands” is a Custom taxonomy, whose slug is “product_brand”. Its a Woocommerce plugin, essentially for adding manufacturers to Woocommerce products.

    I’ve tried printing this code before and it just wasn’t picking up the terms custom field in the print either.

    Do I perhaps need to define “$custom_field” somewhere?

  • Is ‘contact_info’ a field for Category terms or Brand terms? Based on the field that works, I’m guessing the latter, in which case you’ll need to change the 2nd get_field argument:

     $custom_field = get_field('contact_info', 'product_brand_' . $term->term_id);
    
  • I’m not exactly sure where this is supposed to go, so forgive the ignorance but if placed above or between any of the following nothing is returned:

    <?php if(get_field('latest_news_or_reports', $post_object->ID) == "news"): ?>
      <?php query_posts( array ('posts_per_page' => 5, 'order'=> 'DESC', 'orderby' => 'date', 'category__in' => '' ) ); ?> 
      <?php if(have_posts()) : while(have_posts()) : the_post(); ?> 

    If placed below I get:

    Array
      (
      	[36] => stdClass Object
      (
        [term_id] => 36
        [name] => Events
        [slug] => events
        [term_group] => 0
        [term_taxonomy_id] => 36
        [taxonomy] => category
        [description] => 
        [parent] => 0
        [count] => 3
        [object_id] => 2470
      )
    
    )

    Which seems to indicate its grabbing the details from the most recent post (which is something in the Events category with an ID of 2470).

  • @wells5609 @elliot
    Ok, so I managed to get this code to work to get a specific taxonomy ID (so I know the system is working)

    
    <p><?php // the_field('contact_info', 'product_brand_14'); ?></p>
    

    But trying to get the same terms of the current Term ID being displayed, doesn't work however. (In my “archive-brands” template.) Even with array_pop.

    
    <?php
     
    global $post;
     
    // load all 'category' terms for the post
     $terms = get_the_terms($post->ID, "product_brand");
     
    // we will use the first term to load ACF data from
    if( !empty($terms) )
    {
    	$term = array_pop($terms);
     
    	$custom_field = get_field('contact_info', 'category_' . $term->term_id );
     
    	// do something with $custom_field
    }
     
    ?>
    

    Thanks guys

  • Seems like the $terms array is empty… You can test it with this code:

    
    <?php 
    
    $terms = get_the_terms( $post->ID, 'category' );  
    
    echo '<pre>';
    	print_r( $terms );
    echo '</pre>';
    die;
    
    ?>
    
    Can you confirm that 'category' is the correct taxonomy and $post->ID is the correct post ID?
    
  • Hi @udapud

    Instead of using


    $term = $terms[0];

    Can you try

    
    $term = array_pop($terms);
    

    Does that fix the issue?

  • I had this exact same issue!

    Not sure if this helps, but I was using the Taxonomy Field add-on by Brian Zoetewey previously, and disabled this when ACF gained this functionality. However the bug still remained. Today I removed the Taxonomy Field Add-On completely, and upgraded ACF to the latest version, and this functionality started working perfectly!! Such a winning feature.

    One question though – it would be awesome if you could present the option to hide a CPT meta box from a edit screen? As it is, you can only hide default cateogies or tags. However, if we are using this feature, there is a good chance we are using a custom taxonomy that we want to hide – as we are replacing the default taxonomy meta box with our shiny new ACF meta box.

    I know you can ‘hide’ this from the options panel up top, but a sneaky client might find this, and then have the ability to choose multiple tickboxes again 🙂 Be good to hide it permanetly if possible.

Viewing 25 results - 3,151 through 3,175 (of 3,197 total)