Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

reply

  • Ended up replacing the custom checkbox field with another custom taxonomy.

  • Another update… Turns out that the database can’t find any posts using the code examples from the documentation and it’s not possible to use the IN operator for checkboxes. I could only find results with the following SQL:

    SELECT * FROM cms_posts INNER JOIN cms_postmeta ON( cms_posts.ID = cms_postmeta.post_id ) WHERE 1 = 1 AND( ( cms_postmeta.meta_key = 'pb_region' AND cms_postmeta.meta_value LIKE '%eu%' ) ) GROUP BY cms_posts.ID ORDER BY cms_posts.post_title ASC;

    And the posts get filtered only if I set custom arguments in the template itself and manually setting the meta_query but not when using pre_get_posts(I already checked if there was another instance overriding it, there isn’t).

    This is the query when looping through a custom query and meta_query defined with a string value:

    WP_Query Object
    (
        [query] => Array
            (
                [post_type] => products
                [orderby] => title
                [order] => ASC
                [posts_per_page] => -1
                [tax_query] => Array
                    (
                        [taxonomy] => games
                        [term] => totk
                    )
    
                [meta_query] => Array
                    (
                        [0] => Array
                            (
                                [key] => pb_region
                                [value] => eu
                                [compare] => LIKE
                            )
    
                    )
    
            )
    
        [query_vars] => Array
            (
                [post_type] => products
                [orderby] => title
                [order] => ASC
                [posts_per_page] => -1
                [tax_query] => Array
                    (
                        [taxonomy] => games
                        [term] => totk
                    )
    
                [meta_query] => Array
                    (
                        [0] => Array
                            (
                                [key] => pb_region
                                [value] => eu
                                [compare] => LIKE
                            )
    
                    )
                [...]
            )
    
        [...]
        [meta_query] => WP_Meta_Query Object
            (
                [queries] => Array
                    (
                        [0] => Array
                            (
                                [key] => pb_region
                                [value] => eu
                                [compare] => LIKE
                            )
    
                        [relation] => OR
                    )
    
                [relation] => AND
                [meta_table] => cms_postmeta
                [meta_id_column] => post_id
                [primary_table] => cms_posts
                [primary_id_column] => ID
                [table_aliases:protected] => Array
                    (
                        [0] => cms_postmeta
                    )
    
                [clauses:protected] => Array
                    (
                        [cms_postmeta] => Array
                            (
                                [key] => pb_region
                                [value] => eu
                                [compare] => LIKE
                                [compare_key] => =
                                [alias] => cms_postmeta
                                [cast] => CHAR
                            )
    
                    )
    
                [has_or_relation:protected] => 
            )
        [...]
    

    This is my current code, by the way:

    $meta_query = array(
    	'key'       => $name,
    	'value'     => $value,
    	'compare'   => 'LIKE'
    );

    Any input would be much appreciated.

  • Taxonomies aren’t children of one another. Taxonomy terms can be hierarchical to where they can have parent/child relationships (like categories.)

    When registering a taxonomy, you just make sure the hierarchical toggle is on if that’s what you want. If it’s not on, the terms cannot have parent/child relationships and be nested. If hierarchical is on, they can be and when you go to create terms in that taxonomy, you should see the ability to set an existing term within that taxonomy as the parent.

  • (my reply got deleted somehow after editing so I’m reposting…)

    I did some more debugging and noticed that meta_query is getting populated (inside query_vars) but it still doesn’t filter the posts. The loop remains unaffected and all posts are being displayed on both the taxonomy page and custom post type archive instead of getting filtered by the custom field pb_region => region.

    Here’s what $query outputs currently on the taxonomy page after setting meta_query:

    WP_Query Object
    (
        [query] => Array
            (
                [games] => totk
            )
    
        [query_vars] => Array
            (
                [games] => totk
                [error] => 
                [m] => 
                [p] => 0
                [post_parent] => 
                [subpost] => 
                [subpost_id] => 
                [attachment] => 
                [attachment_id] => 0
                [name] => 
                [pagename] => 
                [page_id] => 0
                [second] => 
                [minute] => 
                [hour] => 
                [day] => 0
                [monthnum] => 0
                [year] => 0
                [w] => 0
                [category_name] => 
                [tag] => 
                [cat] => 
                [tag_id] => 
                [author] => 
                [author_name] => 
                [feed] => 
                [tb] => 
                [paged] => 0
                [meta_key] => 
                [meta_value] => 
                [preview] => 
                [s] => 
                [sentence] => 
                [title] => 
                [fields] => 
                [menu_order] => 
                [embed] => 
                [category__in] => Array
                    (
                    )
    
                [category__not_in] => Array
                    (
                    )
    
                [category__and] => Array
                    (
                    )
    
                [post__in] => Array
                    (
                    )
    
                [post__not_in] => Array
                    (
                    )
    
                [post_name__in] => Array
                    (
                    )
    
                [tag__in] => Array
                    (
                    )
    
                [tag__not_in] => Array
                    (
                    )
    
                [tag__and] => Array
                    (
                    )
    
                [tag_slug__in] => Array
                    (
                    )
    
                [tag_slug__and] => Array
                    (
                    )
    
                [post_parent__in] => Array
                    (
                    )
    
                [post_parent__not_in] => Array
                    (
                    )
    
                [author__in] => Array
                    (
                    )
    
                [author__not_in] => Array
                    (
                    )
    
                [search_columns] => Array
                    (
                    )
    
                [meta_query] => Array
                    (
                        [key] => region
                        [value] => Array
                            (
                                [0] => eu
                                [1] => na
                            )
    
                        [compare] => IN
                    )
    
            )
    
        [tax_query] => WP_Tax_Query Object
            (
                [queries] => Array
                    (
                        [0] => Array
                            (
                                [taxonomy] => games
                                [terms] => Array
                                    (
                                        [0] => totk
                                    )
    
                                [field] => slug
                                [operator] => IN
                                [include_children] => 1
                            )
    
                    )
    
                [relation] => AND
                [table_aliases:protected] => Array
                    (
                    )
    
                [queried_terms] => Array
                    (
                        [games] => Array
                            (
                                [terms] => Array
                                    (
                                        [0] => totk
                                    )
    
                                [field] => slug
                            )
    
                    )
    
                [primary_table] => 
                [primary_id_column] => 
            )
    
        [meta_query] => 
        [date_query] => 
        [post_count] => 0
        [current_post] => -1
        [in_the_loop] => 
        [comment_count] => 0
        [current_comment] => -1
        [found_posts] => 0
        [max_num_pages] => 0
        [max_num_comment_pages] => 0
        [is_single] => 
        [is_preview] => 
        [is_page] => 
        [is_archive] => 1
        [is_date] => 
        [is_year] => 
        [is_month] => 
        [is_day] => 
        [is_time] => 
        [is_author] => 
        [is_category] => 
        [is_tag] => 
        [is_tax] => 1
        [is_search] => 
        [is_feed] => 
        [is_comment_feed] => 
        [is_trackback] => 
        [is_home] => 
        [is_privacy_policy] => 
        [is_404] => 
        [is_embed] => 
        [is_paged] => 
        [is_admin] => 
        [is_attachment] => 
        [is_singular] => 
        [is_robots] => 
        [is_favicon] => 
        [is_posts_page] => 
        [is_post_type_archive] => 
        [...]
    )

    And this is the template (just excluding the header and footer):

    <?php $term = get_queried_object();  ?>
    
    <?php if ( have_posts() ) : ?>
      <div class="container">
        <div id="primary" class="content products">
          <div class="filters">
            <?php foreach( $GLOBALS['query_filters'] as $key => $name ): 
                
              // get the field's settings without attempting to load a value
              $field = get_field_object($key, false, false); 
    
              // set value if available
              if( isset($_GET[ $name ]) ) {
                  
                $field['value'] = explode(',', $_GET[ $name ]);
                  
              }
              
              // create filter
              ?>
              <div class="filter" data-filter="<?php echo $name; ?>">
                <?php create_field( $field ); ?>
              </div>
                
            <?php endforeach; ?>
            <input type="hidden" class="js-filter-url" value="<?php echo home_url('products/' . $term->slug . '/'); ?>" />
          </div>
        </div>
    
        <div class="product-grid">
            <?php
    
            while ( have_posts() ) : the_post();
    
                get_template_part( 'template-parts/post/content', 'product' );
    
            endwhile; ?>
            </div>
        </div>
    
    <?php else : ?>
    
    	<div class="container-s">
    		<div id="primary" class="content">
    			<?php get_template_part( 'template-parts/post/content', 'none' ); ?>
    		</div>
    	</div>
    
    <?php endif; ?>

    This is what $query outputs on the custom post type archive:

    WP_Query Object
    (
        [query] => Array
            (
                [post_type] => products
            )
    
        [query_vars] => Array
            (
                [post_type] => products
                [error] => 
                [m] => 
                [p] => 0
                [post_parent] => 
                [subpost] => 
                [subpost_id] => 
                [attachment] => 
                [attachment_id] => 0
                [name] => 
                [pagename] => 
                [page_id] => 0
                [second] => 
                [minute] => 
                [hour] => 
                [day] => 0
                [monthnum] => 0
                [year] => 0
                [w] => 0
                [category_name] => 
                [tag] => 
                [cat] => 
                [tag_id] => 
                [author] => 
                [author_name] => 
                [feed] => 
                [tb] => 
                [paged] => 0
                [meta_key] => 
                [meta_value] => 
                [preview] => 
                [s] => 
                [sentence] => 
                [title] => 
                [fields] => 
                [menu_order] => 
                [embed] => 
                [category__in] => Array
                    (
                    )
    
                [category__not_in] => Array
                    (
                    )
    
                [category__and] => Array
                    (
                    )
    
                [post__in] => Array
                    (
                    )
    
                [post__not_in] => Array
                    (
                    )
    
                [post_name__in] => Array
                    (
                    )
    
                [tag__in] => Array
                    (
                    )
    
                [tag__not_in] => Array
                    (
                    )
    
                [tag__and] => Array
                    (
                    )
    
                [tag_slug__in] => Array
                    (
                    )
    
                [tag_slug__and] => Array
                    (
                    )
    
                [post_parent__in] => Array
                    (
                    )
    
                [post_parent__not_in] => Array
                    (
                    )
    
                [author__in] => Array
                    (
                    )
    
                [author__not_in] => Array
                    (
                    )
    
                [search_columns] => Array
                    (
                    )
    
                [meta_query] => Array
                    (
                        [key] => region
                        [value] => Array
                            (
                                [0] => as
                            )
    
                        [compare] => IN
                    )
    
            )
    
        [tax_query] => WP_Tax_Query Object
            (
                [queries] => Array
                    (
                    )
    
                [relation] => AND
                [table_aliases:protected] => Array
                    (
                    )
    
                [queried_terms] => Array
                    (
                    )
    
                [primary_table] => 
                [primary_id_column] => 
            )
    
        [meta_query] => 
        [date_query] => 
        [post_count] => 0
        [current_post] => -1
        [in_the_loop] => 
        [comment_count] => 0
        [current_comment] => -1
        [found_posts] => 0
        [max_num_pages] => 0
        [max_num_comment_pages] => 0
        [is_single] => 
        [is_preview] => 
        [is_page] => 
        [is_archive] => 1
        [is_date] => 
        [is_year] => 
        [is_month] => 
        [is_day] => 
        [is_time] => 
        [is_author] => 
        [is_category] => 
        [is_tag] => 
        [is_tax] => 
        [is_search] => 
        [is_feed] => 
        [is_comment_feed] => 
        [is_trackback] => 
        [is_home] => 
        [is_privacy_policy] => 
        [is_404] => 
        [is_embed] => 
        [is_paged] => 
        [is_admin] => 
        [is_attachment] => 
        [is_singular] => 
        [is_robots] => 
        [is_favicon] => 
        [is_posts_page] => 
        [is_post_type_archive] => 1
        [...]
    )

    And the template:

    <?php if ( have_posts() ) : ?>
      <div class="container">
        <div class="filters">
          <?php foreach( $GLOBALS['query_filters'] as $key => $name ): 
              
            // get the field's settings without attempting to load a value
            $field = get_field_object($key, false, false); 
    
            // set value if available
            if( isset($_GET[ $name ]) ) {
                
              $field['value'] = explode(',', $_GET[ $name ]);
                
            }
            
            // create filter
            ?>
            <div class="filter" data-filter="<?php echo $name; ?>">
              <?php create_field( $field ); ?>
            </div>
              
          <?php endforeach; ?>
          <input type="hidden" class="js-filter-url" value="<?php echo home_url('products'); ?>" />
        </div>
    
        <div class="product-grid">
          <?php
          /* Start the Loop */
          while ( have_posts() ) : the_post();
            get_template_part( 'template-parts/post/content', 'product' );
          endwhile; ?>
        </div>
      </div>
    
    <?php else : ?>
    
      <div class="container-s">
        <div id="primary" class="content">
          <?php get_template_part( 'template-parts/post/content', 'none' ); ?>
        </div>
      </div>
    
    <?php endif; ?>

    This is in my functions.php:

    $GLOBALS['query_filters'] = array( 
        'pb_region'   => 'region'
    );
    
    // action
    add_action('pre_get_posts', 'tmr_filter', 10, 1);
    function tmr_filter( $query ) {
        // bail early if is in admin
        if( is_admin() ) return;
    
        // bail early if not main query
        // - allows custom code / plugins to continue working
        if( !$query->is_main_query() ) return;
    
        // get meta query
        $meta_query = $query->get('meta_query');
        
        // loop over filters
        foreach( $GLOBALS['query_filters'] as $key => $name ) {
            
            // continue if not found in url
            if( empty($_GET[ $name ]) ) {
                continue;
            }
    			
            // get the value for this filter
            // eg: http://www.website.com/events?city=melbourne,sydney
            $value = explode(',', $_GET[ $name ]);
    			
            //append meta query
            $meta_query = array(
                'key'       => $name,
                'value'     => $value,
                'compare'   => 'IN'
            );
        } 
        
        // update meta query
       $query->set('meta_query', $meta_query);
    }

    Any pointers? Many thanks in advance!

  • @brettbum I have to agree, I don’t see any reason for this group to appear in other places.

    I will take back what I said about not seeing this to a small extent. There have been reports in the past about category (taxonomy) related location rules not working correctly while using the gutenberg editor.

    As a work around you might consider having 2 rules in each “OR”
    Post Type = Posts
    AND Post Category = {Category}

  • Just saw this old one start up again as well. Rules set up for just 8 categories were showing up on all posts, all pages, even on Media Library items.

    Had a separate set of group rules for the taxonomy of category (added fields to category pages beyond description and name ) and those were not impacted.

    So in case it helps troubleshoot (long shot) maybe there is a prioritization? or more likely it just doesn’t impact taxonomy edit pages.

  • My problem is still not resolved. I updated wordpress and ACF to the latest version.
    I also do not understand why, the created field is displayed in the media library, on the right side near the image.
    Although, in the rule I indicated: Taxonomy = Relevant category
    Has anyone encountered such a problem?

  • Have you enabled “load terms”?

    If that does not work then you will need to do your own coding. By default WP does not support taxonomies for media and it’s quite a bit more complicated than just adding an ACF taxonomy field.

  • WP does not offer the ability to add taxonomies media. While you could add a field for a taxonomy with ACF this would be entirely useless on its own. It would not offer any way to filter using it in WP.

    You would need to add code to do this or find a plugin that offers adding taxonomies to media.

  • I thought i was going crazy.

    The taxonomy terms for existing posts will return normally while the new post won’t return anything in the save_post hook.

    I have three settings checked : Create, Save, Load terms.

    Setting priority to 20 (from 10) seems to have solved the problem. Thanks @gingerlyco.

  • I assume you mean if you have a taxonomy under WooComm, you are saying that you have a product post type with a new taxonomy of Brand, right? And then each term in that taxonomy (Brand A, Brand B, Brand C) has a field that has a shipping time associated with it. And that you have found some way (there are a few methods) to limit each product to a single brand term. Yes?

    Then I am not sure why you would want to copy this field elsewhere – would you not just use it in the original location? (Having the same data in 2 places just invites it to be wrong somewhere.) You can pull out the information using this:
    https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

    If you really want it in 2 places, you can also use that method to pull out the taxonomy term field value and stuff it into an update_field on the acf/save_post hook.
    https://www.advancedcustomfields.com/resources/acf-save_post/
    See the “applied after save” section and then
    https://www.advancedcustomfields.com/resources/update_field/

  • This reply has been marked as private.
  • Forum won’t let me edit my last post for some reason. In fact, it disappeared. Here is the complete solution that’s working:

    $args = array(
        'taxonomy' => 'product_cat',
        'meta_query' => array(
          array(
            'key' => 'category_user',
            'value' => $current_user->ID,
            'compare' => 'LIKE',
          )
        ),
        'fields' => 'ids' // return just a list of term IDs
      );
      $terms = get_terms( $args );
    
      $args = array(
        'post_type' => 'product',
        'tax_query' => array(
          array(
            'taxonomy' => 'product_cat',
            'field' => 'term_id',
            'terms' => $terms
          )
        )
      );
      $query = new WP_Query( $args );
  • Thank you John. Below is the complete solutionmodel for anyone looking for this setup and/or solution in the future:

    'value' => '"'.$current_user->ID.'"', had to be 'value' => $current_user->ID, or 'value' => get_current_user_id(),
    'taxonomy_query' => array(... had to be 'tax_query' => array(...
    'field' => 'term_id', had to be added to the tax_query arguments

    Complete solution:

    $args = array(
        'taxonomy' => 'product_cat',
        'meta_query' => array(
          array(
            'key' => 'category_user',
            'value' => $current_user->ID,
            'compare' => 'LIKE',
          )
        ),
        'fields' => 'ids' // return just a list of term IDs
      );
      $terms = get_terms( $args );
    
      $args = array(
        'post_type' => 'product',
        'tax_query' => array(
          array(
            'taxonomy' => 'product_cat',
            'field' => 'term_id',
            'terms' => $terms
          )
        )
      );
      $query = new WP_Query( $args );
  • When I plug in the correct values for taxonomy and key, it simply returns all products. Also when I try and just echo the $terms alone to see what they’re returning, it just says “Array.”

    Here is the code:

    $args = array(
        'taxonomy' => 'product_cat',
        'meta_query' => array(
          array(
            'key' => 'category_user',
            'value' => '"'.$current_user->ID.'"',
            'compare' => 'LIKE',
          )
        ),
        'fields' => 'ids' // return just a list of term IDs
      );
      $terms = get_terms( $args );
    
      $args = array(
        'post_type' => 'product',
        'taxonomy_query' => array(
          array(
            'taxonomy' => 'product_cat',
            'terms' => $terms,
          )
        )
      );
      $query = new WP_Query( $args );
  • The following may not have all the arguments you need.

    
    $args = array(
      'taxonomy' => 'TAXONOMY NAME'
      'meta_query' => array(
        array(
          'key' => 'FIELD NAME'
          'value' => '"'.$current_user->ID.'"',
          'compare' => 'LIKE'
        )
      ),
      'fields' => 'ids' // return just a list of term IDs
    );
    $terms = get_terms($args);
    
    $args = array(
      'post_type' => 'product'
      'taxonomy_query' => array(
        array(
          'taxonomy' => 'TAXONOMY NAME',
          'terms' => $terms
        )
      )
    );
    $query = new WP_Query($args);
    
  • You cannot do this with only a query on the posts (products) because the user field is not associated with the posts, it is associated with a term (category).

    What you will need to do is first to use get_terms() with a meta_query to get a list of terms that are associated with the user. Using this you then query the posts using a taxonomy_query of the terms found in the first step.

  • I tried the below but it is not working.

    $args = array(
        'posts_per_page' => -1,
        'post_type' => 'product',
        'taxonomy' => 'product_cat',
        //Tries to show products from categories where current user ID is in the category_user field
        'meta_query' => array(
          array(
            'key' => 'category_user',
            'value' => '"' . $current_user->ID . '"',
            'compare' => 'LIKE'
          )
        )
      );
  • i resolved putting in the array taxonomy ids as strings

  • It looks like you are adding fields to a term in a taxonomy. To display the fields you must include a $post_id argument in the ACF function.

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

  • You would need to build an array of term IDs to use in the “include” argument

    
    $children = get_term_children($term_id, 'TAXONOMY');
    $include = array_merge(array($term_id), $children);
    $args['include'] = $include;
    
  • Try this css:
    .acf-fields.-taxonomy input[type=”checkbox”] {
    display: block;
    width: 100%;
    margin-bottom: 10px;
    }

    .acf-fields.-taxonomy .acf-checkbox-list {
    column-count: 3;
    column-gap: 20px;
    }

  • It’s really hard to think no one else had this problem in all this time. I’m in the same exact spot you are @hopkirk.
    I’ve been the last month trying every single frontend form out there and with everyone there is a BIG problem.

    With ACF is not being able to exclude terms in the taxonomy list (which can be worked around by using ACF extended) and this gallery in mobile issue, which is really something important.

    Just to add up a little more information. From android, it does NOT work. When you tap on an image, nothing happens. From iOS the pop up appears, but because of the CSS misplacing, you can not delete the image.

    If anyone has a solution to this, I will be very, very grateful.

  • It wouldn’t be in the wp_options table. If you attach a field to a taxonomy term, it would be in the wp_termmeta table for that term. It would be the name of your field in the termmeta attached to the shows taxonomy term you adjusted the actors field for.

    Also the field in the database does not include the term-slug_term-id. It’s just the info you pass to the get_field ACF function to know where to find your ACF field’s data.

Viewing 25 results - 726 through 750 (of 3,193 total)