Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

reply

  • Here is with meta_query args but it didn’t work, I have the same results.
    There is something I don’t understands.

    
    add_action( 'pre_get_posts', 'films_query' );
    function films_query( $query ) {
      if ( !is_admin() && $query->is_main_query() && is_post_type_archive( 'films' ) ) {
        $cat_hide = get_field('categorie_des_films_a_masquer', 'options');
        $taxquery = array(
          array(
            'taxonomy' => 'categorie_films',
            'field' => 'term_id',
            'terms'    => $cat_hide,
            'operator' => 'NOT IN',
          )
        );
    
        $query->set( 'posts_per_page', '-1' );
        $query->set( 'post_status', 'publish' );
    
        $query->set( 'tax_query', $taxquery );
        $query->set( 'meta_query', array(
          'relation' => 'AND',
          'date' => array(
            'key' => 'date_de_sortie',
            'compare' => 'EXISTS',
          )
        )
      );
      $query->set( 'orderby', array(
        'date' => 'ASC',
        'title'   => 'ASC',
      )
    );
    }
    }
    
  • doing something like this would be more complicated than adding a field to the category. When saved the value would be saved to the category and not indicated what user is following.

    This is not something that can’t really be done with ACF. You need to record information based on the user, probably in user meta, that stores a list of categories they are following and then query based on the value stored for the current user.

    You could potentially use an ACF Taxonomy field on the user admin page and then use AJAX to store values to the current users page.

  • You have some issues in your code, for example this

    
    if ($result = term_exists($term, $taxonomy)) {
    

    should probably be

    
    if ($result == term_exists($term, $taxonomy)) {
    

    there are several of this same type of error in the code that you’ve posted.
    This is usually why some people code like this

    
    if (term_exists($term, $taxonomy) == $result) {
    

    because the above would create an error if you use ‘=’ instead of ‘==’ rather than fail quietly.

  • Thanks for the follow up @hube2. I was trying to order the posts by that field (basically I big list of the shows in that taxonomy). I ended up using a javascript table sorter to adjust the output after ACF was done with it. I couldn’t figure it out and if YOU are saying it’s a lot of work then 100% I’d never figure it out — I’m just a code scavenger. 🙂 Thanks.

  • This plugin might help you. You can export and import many field data along with images, taxonomy, and options.

    https://wordpress.org/plugins/simple-export-import-for-acf-data/

  • in post type stories have taxonomy is Chapter, that have value is video manga text.
    if i create radio button field in post type stories and create Choices that
    video : Video
    manga : Cartoon
    text : Novel
    how to set radio button choices with taxonomy value?

  • Hi John,

    I managed to fix this issue by installing the “Taxonomy Order” plugin, so the issue is taken care of.

    Thanks for your help and explanation.

  • Here’s my code if it’s of any help to others.

    This is my solution to adding custom fields targeting specifically the children of parent categories.
    i.e.:

    • Locations

      • Los Angeles, CA
      • Denver, CO
      • New York, NY

    (Credit to Kellen Mace for the snippet on finding the current category edit page. Link in the code.)

    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly
    }
    
    class ACF_Category_Name_Location extends ACF_Location {
        public function initialize() {
            $this->name         = 'category_name';
            $this->category     = __( 'Category', 'acf');
            $this->label        = __( 'Category Name', 'acf' );
            $this->object_type  = 'post';
        }
    
        public function get_values( $rule ) {
            $choices = array();
    
            // Load all category terms, loop over them and append to choices.
            $terms = get_terms( array(
                'taxonomy' => 'category',
                'orderby' => 'name',
                'hide_empty' => false,
                'parent' => 0,
            ) );
    
            if( $terms ) {
                foreach( $terms as $term ) {
                    $choices[ $term->term_id ] = $term->name;
                }
            }
    
            return $choices;
        }
    
        public function match( $rule, $screen, $field_group ) {
            /**
             * https://kellenmace.com/get-term-edited-term-php-wordpress-admin-page/
             */
            // Get the term currently being edited on the edit.php screen in the WP admin.
            global $taxnow;
    
            if ( ! $taxnow || empty( $_GET['tag_ID'] ) ) {
                return false;
            }
    
            $term_id = absint( $_GET['tag_ID'] );
    	    $term    = get_term( $term_id, $taxnow );
    
            // return false if not and instance of WP_Term
            if ( ! $term instanceof WP_Term ) {
                return false;
            }
    
            // Compare the selected terms parent to rule value.
            $result = ( $term->parent == $rule['value'] );
    
            // Return result taking into account the operator type.
            if( $rule['operator'] == '!=' ) {
                return !$result;
            }
    
            return $result;
        }
    }
    
  • Here’s my code for anyone that this might help.

    This is my solution to specifically targeting children of parent categories:
    i.e.:

    • Locations

      • Los Angeles, CA
      • Denver, CO
      • New York, NY

    (Credit to Kellen Mace for a snippet to identify the current taxonomy admin page. Link in the code.)

    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly
    }
    
    class ACF_Category_Name_Location extends ACF_Location {
        public function initialize() {
            $this->name         = 'category_name';
            $this->category     = __( 'Category', 'acf');
            $this->label        = __( 'Category Name', 'acf' );
            $this->object_type  = 'post';
        }
    
        public function get_values( $rule ) {
            $choices = array();
    
            // Load all category terms, loop over them and append to choices.
            $terms = get_terms( array(
                'taxonomy' => 'category',
                'orderby' => 'name',
                'hide_empty' => false,
                'parent' => 0,
            ) );
    
            if( $terms ) {
                foreach( $terms as $term ) {
                    $choices[ $term->term_id ] = $term->name;
                }
            }
    
            return $choices;
        }
    
        public function match( $rule, $screen, $field_group ) {
            /**
             * https://kellenmace.com/get-term-edited-term-php-wordpress-admin-page/
             */
            // Get the term currently being edited on the edit.php screen in the admin.
            global $taxnow;
    
            if ( ! $taxnow || empty( $_GET['tag_ID'] ) ) {
                return false;
            }
    
            $term_id = absint( $_GET['tag_ID'] );
    	    $term    = get_term( $term_id, $taxnow );
    
            // Return false if not WP_Term
            if ( ! $term instanceof WP_Term ) {
                return false;
            }
    
            // Compare the current term parent to rule value.
            $result = ( $term->parent == $rule['value'] );
    
            // Return result taking into account the operator type.
            if( $rule['operator'] == '!=' ) {
                return !$result;
            }
    
            return $result;
        }
    }
  • Yes, you can only add fields to all terms in a taxonomy, not specific terms. Do do this you’d need to create a custom location rule. Sorry, I don’t have any code for this and I can’t find any. I’m sure that there is an example of this on this forum, or a link to it, but I can’t seem to locate it.

  • Having the exact same issue. Created taxonomies for Locations with CPT UI. I can select them fine in the backend, but when it comes to Elementor, the taxonomy fields are not available for selection.

  • Maybe I’m misunderstanding the abilities of targeting by taxonomy. Is it only for adding fields to ALL categories? No way of having fields available only on SPECIFIC categories?

    For instance in my example above, I have two categories: Campuses and Cities, but I only want custom fields on my Campuses category. Can I target that granular?

  • I don’t see anything wrong with the original location rules

    Taxonomy is equal to category should put the fields on the term editor page when ediging any category.

    What other plugins are you using. The only thing I can think of if it is adding fields to other categories is some type of conflict.

  • Serving as an update to my reply from yesterday, I thought that since adding the fields to only the Taxonomy -> Category was too general, increasing the specificity with an addition Location option would be the best next move. But everything gets completely removed. @hube2 would you have any other recommendations? Or is this an actual bug?

    Increasing Location specificity
    I’ve also tried with Post Taxonomy instead of Post Category:
    Increasing Location specificity with Post Taxonomy
    No fields added to default category page
    Also no fields added to custom category page

  • What template file are you making changes to. I’m assuming “taxonomy-review-series.php”. I’ve never used get_queried_object_id(), and I learned something new today. I generally do something like

    
    $queried_object = get_queried_object();
    $value = get_field('field_name', $queried_object);
    

    If you are working in a template file that is showing a specific term in a taxonomy then this should work.

  • I’m running the newest version (5.12.3)

    I had a suspicion that it might have been old documentation, but with only the Taxonomy location specified, it adds it too many places.

    Application of Taxonomy location
    Category Page
    Custom Category

  • 
    if (get_field( 'review_series_featured_image', 'term_'.$archive_id ) {
    

    https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

  • What version of ACF are you using?

    The latest version of ACF does not have a “Taxonomy Term” location rule, only a “Taxonomy”. The doc is old. Choose “Taxonomy is equal to {the taxonomy you want the fields on}”

  • The issue is that you have added a filter specifying 2 arguments to be passed but your function requires 3 arguments.

    
    // 4th parameter is number of args to pass = 2
    add_filter('acf/fields/taxonomy/query/key=field_62d02ad58c59f', 'my_acf_fields_taxonomy_query', 10, 2);
    // function requires 3 args
    function my_acf_fields_taxonomy_query( $args, $field, $post_id ) {
        // Order by most used.
        $args['parent'] = 0;
        
        return $args;
    }
    
  • @hube2 yes essentially that

    if i add the “Disable Gutenberg” plugin then the fields wont reload until I publish with the taxonomy first time anyway which reloads the page. After that the fields save fine

    it’s the Guternberg / Ajax metabox loading that’s causing the problem as mentioned by Liam in the issue above

  • Taxonomy = Relevant category
    also tried
    Category = Relevant category

  • Just to clarify, you wrote:

    In order for fields to appear and for there to be a location the page must be either post type of a taxonomy.

    Did you mean: “the page must be either a post type or a taxonomy?

  • In order for fields to appear and for there to be a location the page must be either post type of a taxonomy. The URL indicates a custom admin page

    edit.php?post_type=course&page=sensei_grading&user=1&quiz_id=4332

    This cannot be used for an acf location rule because this page does not call any of the hooks used by ACF for adding custom fields.

    This type of page is similar to the page located at options-general.php. ACF cannot be used to add fields to these places.

    To do this would require altering the template or function that shows the form on the page and using acf_form() with the “form” argument set to false to insert the ACF form between the form tags of the other existing form. Depending on the plugin it might be possible that they provide some type of hook to do this but not in most cases. You need to contact the developer of the other plugin and find out if they provide any mechanism for modifying the form on that admin page.

  • Kind of, the taxonomies are:

    Shows
    Country
    Topics

    Under shows I can assign a topic, and the country (amongst other fields) via ACF. The code I added at the top allows me to display a list of Show Taxonomy items based on the country field (podcast_country) – it’s a single item so I used a text field and the query was quite easy to create.

    What I’m trying to do is list the Shows based on the ‘podcast_topic’ field, but because that’s a taxonomy it outputs as an array and I can’t figure out how to get it to work.

    shows taxonomy

Viewing 25 results - 801 through 825 (of 3,193 total)