Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

topic

  • Unread

    Use url parameters to sort results of relational field query

    Background:
    The goal is to use query parameters to filter results of a relationship field by a custom taxonomy using a select dropdown, which is populated with that custom taxonomy from the posts that have been selected from the relationship field.

    Problem:

    I have a relational field that comprising of posts from a Product custom post type. On the page where these results are displayed, I have a dropdown selection that pulls the custom taxonomy, named product-tag, from these Products and that populates the dropdown selections. The user selects the product tag from the dropdown and I want to filter the results by a query parameter, like this: website.com/?product-tag=tagName. I’ve tried a variety of approaches, building off of this tutorial https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/. But the difference here is I’m not filtering posts from the main query, but instead from a custom field relationship query – and I can’t seem to get that to work.

    Appreciate any direction. Thanks!

  • Unread

    Taxonomy Image Not Showing off all child categories

    I am trying to show taxnomy image but I can’t do this please help

    <?php
                        $category = get_category( get_query_var( 'cat' ) );
                        $cat_id = $category->cat_ID;
                        $category_per_page = 2;
                        $page = 1;
                        $offset = 0;
    
                        $taxonomy = 'category';
                        if (!empty($_GET['page'])){
                            $offset = ($_GET['page'] - 1) * $category_per_page;
                        }
    
                        $tax_terms = get_terms( $taxonomy, array( 'parent' => $cat_id,'number' => $category_per_page, 'offset' => $offset , 'hide_empty' => false ) );
                        $totalCategories = get_terms( $taxonomy, array( 'parent' => $cat_id, 'hide_empty' => false ) );
                        $totalNumber = sizeof($totalCategories);
                        $totalPagination = round($totalNumber / $category_per_page);
    $current_term = get_queried_object(); 
                        foreach ($tax_terms as $tax_term) :
                            $args=array('cat' => $tax_term->term_id,'showposts'=>16);
                            $query=new WP_Query($args);
                    ?>
                    <div class="col-xs-12">
                        <div class="heading">
                           <?php
    $images = get_field('cat_img', $taxonomy . '_' . $tax_term->term_id );
    
    	echo '<img src="'.$images.'"/>';
    	?><h3 class="heading-title"><a href="<?=esc_attr(get_term_link($tax_term, $taxonomy));?>" title="<?=the_title();?>"><?= $tax_term->name;?></a></h3>
                        </div>
                       
                    </div>
                    <?php endforeach;?>
  • Solving

    Sort Custom Post Type by Taxonomy.

    Hi
    I have a query I would like to resolve.

    The scenario is as follows:
    I have a custom post type called Auction.

    Auctions have an acf in relation to a custom post type product.
    Those products can be assigned taxonomies.

    My question is how to sort those products by taxonomy when I’m on the single-auction.php page.

    Following the documentation I can show all the products of an auction, but I would like to sort those products by their taxonomy.

    An image to clarify what I want to get :

    A brief explanation:

    Taxonomy Term A

    Product 1
    Product 2

    Taxonomy Term B

    Product 3
    Product 4
    Order custom post type by taxonomy

    My code :

    $featured_posts = get_field(‘products_in_this_auction’);
    (Note: get_field(‘products_in_this_auction’) is a Post Object)
    This is a post object and contains the ids of the products that are linked to the auction.

    But my problem is how to get those products sorted by taxonomy.
    I guess I have to use tax_query for my
    query.

    I have an old code that shows me all the custom post type products ordered by their taxonomy, as seen in the image, but what I need is to show only the custom post type products that depend on the current auction.

    I know those custom post type are in $featured_posts = get_field(‘products_in_this_auction’); but I don’t know how to get them.

    My code, something old-fashioned, is the following.

     $categories = get_terms('type_produc', 'orderby=count&order=DESC&hide_empty=1');
                          foreach( $categories as $category ): 
                          ?>
                          <h3 class="title_pru"><?php echo $category->name; // Prints the cat/taxonomy group title ?></h3>
                          <?php
                          $posts = get_posts(array(
                          'post_type' => 'myproduct',
                          'taxonomy' => $category->taxonomy,
                          'term' => $category->slug,
                          'nopaging' => true,
                          ));
                          foreach($posts as $post): 
                          setup_postdata($post); 
                          ?>
                         
                          <div id="post-<?php the_ID(); ?>">
                         
                        
                        <?php  the_title( sprintf( '<p class="title_pru"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></p>' ); ?>
                         
                       
                         
                          </div><!-- #post-## --> 
                          <?php endforeach; ?>
                         
                         <?php endforeach; ?>

    This code shows the result of the image, but it doesn’t work for me.

    I hope someone can help.
    Thank you very much.

  • Solved

    Set Default Taxonomy

    Hi All,

    I’m hoping someone can help!?

    I’ve got an ACF Taxonomy called Custom Stock Status (custom_stock_status)

    It pulls in from a WooCommerce Attribute (taxonomy) called Custom Stock Status (pa_custom-stock-status)

    It has a value of Available to Order ( slug available-to-order )

    My understanding is I can set that value doing something like:
    $term_taxonomy_ids = wp_set_object_terms( $post->ID, 'available-to-order', 'custom_stock_status');
    However, I can’t seem to get it to work.

    The idea being when a products created, I can use the following code to preset the attribute:

    
    add_action('save_post_product', 'initiate_product', 10, 3);
    function initiate_product($postID, $post, $update) {
        if (!$update) {
            // $update is false if we're creating a new post
    
    	   $term_taxonomy_ids = wp_set_object_terms( $post->ID, 'available-to-order', 'custom_stock_status');	
    
        }
    }
    

    Yet it doesn’t work. I’m clearly missing something obvious, so would be grateful of any pointers!

    Many thanks

  • Solved

    Replicate 3 fields to the Home Page.

    Hi, how can you see in the link I have built loops for songs in ACF.
    https://rgmusic.net/music/

    Each loop contains:
    Title (Text Field)
    Tags (Taxonomy)
    file.mp3 (File)

    But I would like to create a new field that can select 3 options and allow me to send the title field, tags and .mp3 file to the HOME page.
    https://rgmusic.net/

    In other words, you can choose what, in addition to the songs appearing on the MUSIC page, the song you choose can appear in any of the three sections on the HOME page.

    Treding Track (Button)
    New Releases (Button)
    Popular (Button)

    What kind of field or relation do I need to solve this problem.

    I would be very grateful if you could help me.

  • Solving

    Hide empty categories

    Hi all,

    So I have two custom post types, Media and Artist. Artists add each image or film as a new post (Media), there is a relationship field for each media post titled ‘Artist’, so when adding an image they select the associated artist.

    Another the artist will do is select a category for the media post. This is so that on the artist page when pulling in the artist content, there is an option to then filter based on the Media category.

    I can output the categories but the problem is, it shows all categories, regardless if the artist has content for a particular category or not. Is there any way to hide hidden categories and possible hide filters alltogether if there is only 1?

    Here is the code I am using to output the category filters:

    			<div class="filter-btn">	
    				<ul id="buttons">
    					<li class="active" data-target="artists">All Work</li>
    					<?php 
    					$categories = get_categories( array(
    						'taxonomy'  => 'media_category',
    						'orderby' => 'name',
    						'parent'  => 0,
    						'hide_empty' => true,
    					) );
    					foreach ( $categories as $category ) {
    						printf( '<li data-target="%2$s">%2$s</li>',
    							esc_url( get_category_link( $category->term_id ) ),
    							esc_html( $category->name )
    						);
    					}
    					?>
    				</ul>
    			</div> 	

    Any help would be fantastic.

    Thanks
    Lee

  • Solving

    Get terms/taxonomy form

    Hey, so I have a custom admin dashboard page where I display the terms hierarchy (for a better UX).

    At this point I’m trying to display the form from product_cat taxonomy term using acf_form.

    I tried setting the post_id with
    1. The term object
    2. ‘product_cat_’ . $term_id
    3. ‘term_’ . $term_id
    4. ‘term_product_cat_’ . $term_id (and sideways)

    None of this actually worked. Am I doing something wrong? Or does this function work only with post_types?

    If it’s not supported for terms – is it any way to display a Term form with custom fields from ACF

  • Unread

    Post object with taxonomy selection not working in acf frontend

    I have made a taxonomy with car type with two options
    1-sale
    2.-parts

    I select a post from (add car) and select taxonomy (sale)

    But when i made a Post Object field with post of (add car) to select post that has category selected (sale) its showing empty but when i remove the taxonomy select options and select the category has whole (car type ) it shows all the posts ???
    how can i fix this

  • Unread

    add object/ID to link field return array?

    Hi- I’m using the link field as part of a custom navigation I needed to build out (using standard menus wasn’t going to cut it for the kooky design the creative team came up with)… The link field is great because it allows for selecting any piece of content within the site or external links, and offers a target option.

    However, it’d be really handy if the return array [‘url’,’title’,’target’] also contained an object ID and type in the array..

    Eg. if the linked item was a post, it could return ['url','title','target','type'=>'post','id'=>$post_id]

    A custom post type could return
    ['url','title','target','type'=>$post_type_handle,'id'=>$post_id]

    While a taxonomy archive could return
    ['url','title','target','type'=>$taxonomy,'id'=>$term_id]

    Finally, an external link could return
    ['url','title','target','type'=>'external','id'=>null]

    And so forth..

    Maybe I’ll work on it myself and submit a PR for it.

  • Helping

    Dynamic Taxonomy Field based on Dynamic Select Field

    Hi – I’m basically creating a page builder with Flexible Content and I’d like to include a ‘Post Grid’ template that allows users to choose which post type they want to display and then give the option to choose a category if they like. What I have at the moment is a select field for the post type that I am dynamically populating with the following:

    add_filter('acf/load_field/name=choose_posts', 'acf_load_post_types');
    
    function acf_load_post_types( $field ) {
    
        $choices = get_post_types( array( 
            'public'   => true,), 'objects' );
            unset( $choices['attachment'] );
            unset( $choices['page'] );
            foreach ( $choices as $post_type ) :
                $field['choices'][$post_type->name] = $post_type->labels->singular_name;
            endforeach;
            return $field;
    }

    This give me a single select field with the options ‘Post, Testimonials, Services’ (default post type and two CPTs). What I would like to do is have another select field that populates with the categories of the selected post type. So if a user selects ‘Services’ the following select field displays ‘Residential, Commercial, etc’. I want this to be dynamic so that I don’t have to go in and create conditional fields based on the sites categories – especially since clients can create their own categories once the site is handed off. Any help would be appreciated. Thanks

  • Solved

    Weird Behavior with Taxonomy field

    Can someone explain to me what might be happening? Or maybe I’m just misunderstanding the documentation for the Taxonomy field. I’m seeing two issues, one with the “Save Terms” option and the other with “Load Terms”. For context, I have a repeater field with one of the subfields as a taxonomy field set to use the default post tags taxonomy.

    When I set the “Save Terms” to true with the intention to make it so whatever tag they set here is also assigned to the post in the sidebar, making it dummy-proof for my editors in case they forget to also assign the tag to the post. But doing so while editing a post wipes out all other tags upon saving and makes it so that the tag assigned in this ACF subfield is the _only_ tag assigned to the post. Obviously this is not what I want, and I just set it to false and hope that my editors remember to assign the same tag they selected in ACF to the actual post.

    As an alternative to the first issue, my second issue is when I set “Load Terms” to true with the idea that _only_ the tags assigned to the post will appear in the drop down, so it forces the editors to assign it first and then use the ACF. However, all tags appear in the drop-down, regardless if any tags are assigned to the post. Even worse, if I have two tags assigned to my post and I use field to point to the second one, after saving, it forcefully points to the first tag. Once again, I set this ACF configuration to false so it at least behaves normally but now I can’t really dummy-proof it for my editors in any capacity.

    Is this the intended behavior of “Save Terms” and “Load Terms” or is something going on? Thanks in advance!

  • Helping

    Query Product categories what have a custom field

    Hello

    Im trying to build a page template on wordpress that will show a list a categories that have a custom field checked.

    So the taxonomy is just the default woocommerce taxonomy product_cat I then have a custom field to the product_cat taxonomy which is a check box called collectable

    My set up is
    Main Category
    – Child
    – Child
    – Child
    – Child

    So for example 2 children categories have the tick box collectable which is set to add the value of 1 into the datbase

    So I am doing a page where it will show all categories with the collectable checked.

    $args = array(
    ‘post-type’ => ‘product’,
    ‘taxonomy’ => ‘product_cat’,
    ‘hide_empty’ => 0
    );
    $c = get_categories($args);
    $c_keep = array();
    foreach($c as $cat){
    if (get_field(‘collectable’, ‘category_’.$cat->term_id)) {
    $c_keep[] = $cat;
    }
    }

    foreach($c_keep as $cat){
    echo $cat->name;
    }

    But I am getting nothing at all returned.

    I even put a

    print_r( $args );

    But I am still coming up with a blank (Header and footer Loads and the text above the query)

    Can anyone help please

  • Solving

    What\'s the mistake here?

    it does not work for me.
    What’s not right here?
    I’m trying to create a filter that will only display one term.
    Thanks

    add_filter('acf/fields/taxonomy/query/name=abc', 'public_term_taxonomy_query', 10, 3);
    function public_term_taxonomy_query( $args, $field, $post_id ) {
        $args[ 'name' ] = [ 'public' ];
        return $args;
    }
  • Unread

    Query posts by field

    Hi, I have got a little problem here,
    I have a post type called “Brand” and a taxonomy called “Category-brand”
    Under the post type “brand” I need to relate a numeric field called “grade” to one of the categories under “category-brand”.
    in the archive page of “category-brand” I need to display his related posts.
    In each post I need to display the grade that related to the current category. (from the repeater)
    The posts need to be ordered by the grades of the related category.

    So I have created a repeater field under the post type with 2 subfileds: numeric filed: “grade” and “category-brand” taxonomy field.

    I succeed to display the grade that related to the current category in each post in the “category-brand” archive, But I can’t order those posts by this grade subfiled (I remind that I need to sort it only by the grade that related to the current category.)

    Anyone Have an a better idea how can I do that?
    Thanks.

  • Unread

    Meta key form repeater sub field , only if value related to current taxonomy

    I have post type called “brand” and taxonomy called “category_brand”. Under the “brand” post type I have a repeater field. That repeater field Includes two sub fields: number field called “grade”, and taxonomy field called “category” (the taxonomy display all the categories under “category_brand”)

    it looks like this: the repeater field

    In the taxonomy archive of “category_brand” I display only the “brands” of the current taxonomy.

    The order of the posts need to be by the “grade” sub fields, (large to small number).

    I’m troubling with getting the ‘meta_key’ from the grade field under the repeater. The thing is that I need to get the “grade” field only if it’s related to the current taxonomy – The “category” sub field in the repeater.

    This is the code

    $current_object=get_queried_object();
    $current_object_tax= $current_object->taxonomy;
    $current_object_tax_id= $current_object->term_id;

    $post_args_current_tax = array(
    ‘post_type’ => ‘brands’,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’=> $current_object_tax,
    ‘field’=> ‘term_id’,
    ‘terms’ => $current_object_tax_id,
    ),
    ),
    ‘posts_per_page’ => -1,
    ‘meta_key’=> ‘categorygrade_0_grade’,
    ‘orderby’=> ‘meta_value_num’,
    ‘order’ => ‘DESC’,
    );
    $post_query_current_tax = new WP_Query($post_args_current_tax);
    Right now this meta_key:’meta_key’=> ‘categorygrade_0_grade’, takes all the grades under the repeater and not only the grades that related to the current taxonomy. How can I get the grade only if it’s related to the current taxonomy in the repeater?

  • Unread

    get Meta key form repeater sub field , only if value related to current taxonomy

    I have post type called “brand” and taxonomy called “category_brand”. Under the “brand” post type I have a repeater field. That repeater field Includes two sub fields: number field called “grade”, and taxonomy field called “category” (the taxonomy display all the categories under “category_brand”)

    it looks like this: the repeater field

    In the taxonomy archive of “category_brand” I display only the “brands” of the current taxonomy.

    The order of the posts need to be by the “grade” sub fields, (large to small number).

    I’m troubling with getting the ‘meta_key’ from the grade field under the repeater. The thing is that I need to get the “grade” field only if it’s related to the current taxonomy – The “category” sub field in the repeater.

    This is the code

    $current_object=get_queried_object();
    $current_object_tax= $current_object->taxonomy;
    $current_object_tax_id= $current_object->term_id;

    $post_args_current_tax = array(
    ‘post_type’ => ‘brands’,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’=> $current_object_tax,
    ‘field’=> ‘term_id’,
    ‘terms’ => $current_object_tax_id,
    ),
    ),
    ‘posts_per_page’ => -1,
    ‘meta_key’=> ‘categorygrade_0_grade’,
    ‘orderby’=> ‘meta_value_num’,
    ‘order’ => ‘DESC’,
    );
    $post_query_current_tax = new WP_Query($post_args_current_tax);
    Right now this meta_key:’meta_key’=> ‘categorygrade_0_grade’, takes all the grades under the repeater and not only the grades that related to the current taxonomy. How can I get the grade only if it’s related to the current taxonomy in the repeater?

  • Helping

    Get Meta key form repeater sub field , only if value related to current taxonomy

    I have post type called “brand” and taxonomy called “category_brand”. Under the “brand” post type I have a repeater field. That repeater field Includes two sub fields: number field called “grade”, and taxonomy field called “category” (the taxonomy display all the categories under “category_brand”)

    it looks like this: the repeater field

    In the taxonomy archive of “category_brand” I display only the “brands” of the current taxonomy.

    The order of the posts need to be by the “grade” sub fields, (large to small number).

    I’m troubling with getting the ‘meta_key’ from the grade field under the repeater. The thing is that I need to get the “grade” field only if it’s related to the current taxonomy – The “category” sub field in the repeater.

    This is the code

    
    $current_object=get_queried_object();
     $current_object_tax= $current_object->taxonomy;
     $current_object_tax_id= $current_object->term_id;
    
    $post_args_current_tax = array(
       'post_type' => 'brands',
        'tax_query' => array(
          array(
          'taxonomy'=>  $current_object_tax,
           'field'=> 'term_id',
          'terms' =>   $current_object_tax_id,
       ),
     ),
         'posts_per_page' =>  -1,
         'meta_key'=> 'categorygrade_0_grade',
         'orderby'=> 'meta_value_num',
         'order'    => 'DESC',
         );
         $post_query_current_tax = new WP_Query($post_args_current_tax);

    Right now this meta_key:’meta_key’=> ‘categorygrade_0_grade’, takes all the grades under the repeater and not only the grades that related to the current taxonomy. How can I get the grade only if it’s related to the current taxonomy in the repeater?

  • Unread

    Get Meta key form repeater sub field , only if value related to current taxonomy

    I have post type called “brand” and taxonomy called “category_brand”. Under the “brand” post type I have a repeater field. That repeater field Includes two sub fields: number field called “grade”, and taxonomy field called “category” (the taxonomy display all the categories under “category_brand”)

    it looks like this: the repeater field

    In the taxonomy archive of “category_brand” I display only the “brands” of the current taxonomy.

    The order of the posts need to be by the “grade” sub fields, (large to small number).

    I’m troubling with getting the ‘meta_key’ from the grade field under the repeater. The thing is that I need to get the “grade” field only if it’s related to the current taxonomy – The “category” sub field in the repeater.

    This is the code

     $current_object=get_queried_object();
     $current_object_tax= $current_object->taxonomy;
     $current_object_tax_id= $current_object->term_id;
    
    $post_args_current_tax = array(
       'post_type' => 'brands',
        'tax_query' => array(
          array(
          'taxonomy'=>  $current_object_tax,
           'field'=> 'term_id',
          'terms' =>   $current_object_tax_id,
       ),
     ),
         'posts_per_page' =>  -1,
         'meta_key'=> 'categorygrade_0_grade',
         'orderby'=> 'meta_value_num',
         'order'    => 'DESC',
         );
         $post_query_current_tax = new WP_Query($post_args_current_tax);

    Right now this meta_key:’meta_key’=> ‘categorygrade_0_grade’, takes all the grades under the repeater and not only the grades that related to the current taxonomy. How can I get the grade only if it’s related to the current taxonomy in the repeater?

  • Helping

    Conditional logic with checkbox

    Hi,

    I’m in a custom-taxonomy template
    I use a loop who works with a get template part.
    I make with ACF a checkBox with the slug bouton_article_format and 4 choice whose patch

    And the idea is if patch is check so put the get template part if not don’t put the get template part.

    My code is this one but is not works …

    $patchButton = get_field('boutton_article_format');
    if ( $patchButton && in_array('patch', $patchButton ) ) {
     get_template_part("template-parts/button-template-loop/button-patch-loop");
    }
    ?>

    I thinks is not works because i use a custom taxonomy template but i’m not sure …

  • Unread

    Display one term from taxonomy

    How can I show one term from taxonomy?
    Thanks

  • Solving

    Populate / Edit Taxonomy Fields on an Edit Screen

    Hey there —

    I have a CPT called “Abstracts.”

    I set up two custom taxonomies — “Abstract Author” and “Abstract Company.”

    I’ve added some ACF fields to those taxonomies — name, address, etc.

    Here’s what I’m trying to accomplish:

    — The user chooses or adds a taxonomy term for the post
    — After choosing the taxonomy term, the ACF fields associated with that term appear on the same edit screen.
    — The user can then edit or newly fill out those field
    — When you publish the post, those ACF fields will save back to the terms assigned.

    Basically, I’m trying to avoid adding a taxonomy term, then saving, then clicking over to the term, then editing the ACF fields, then saving that. I’d like to have it all in one place.

    Does this seem like it’s even possible? Could this be done with a front end form maybe?

  • Solving

    Moving Fields Between Groups

    I wish to move a taxonomy field from one group to another. Both groups are part of posts.

    If I move the field, I assume… that all data is also moved and still linked?

    Could someone confirm this?

  • Unread

    Introducing one term from taxonomy

    I have a taxonomy with a lot of terms, I want to use the field of presenting taxonomy but that will display only one term out of all taxonomy. How can I do it? Would appreciate help

  • Unread

    How to add a slug to a post request?

    Hi, action: acf/fields/taxonomy/add_term
    Can you please tell me how to add a tag slug? when clicked, it sends such a post request:

    
    action: acf/fields/taxonomy/add_term
    field_key: field_5e4169dd2bd3d
    term_name: Name term
    term_parent: 0
    nonce: c9e647a5c2
    post_id: 357
    

    I form this request on the javascript side, I need to understand which parameter to add so that I can immediately put down the slug?

  • Unread

    Taxonomy terms missing from location rules after changing the slug

    I added ACF custom fields to WooCommerce products and assigned them according to their taxonomy terms (product_cat).
    Everything was working fine, but when I changed the slug of some terms the location rules disappeared. And when I wanted to reassign them these terms were no longer in the location rules dropdown.

    These terms are still present because they are selectable in another ACF rule (see image).

    Each time I modify the slug of a term, it disappears from the Taxonomy list of the ACF rules.
    I guess I’m not the only one to have encountered this problem, but I haven’t found anything in my research. Is it an ACF bug or a problem on my side?

    Thanks,
    Laurent Leruste

Viewing 25 results - 551 through 575 (of 3,191 total)