Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

reply

  • I was founding the solution about (to change the Filter text “select taxonomy” to “Select city”) after reaching this page, Query solved! and I get more knowledge about it here’s my site https://animenexty.com/ You can also check it by clicking on that link. My site is working properly.
    function my_acf_input_admin_footer() {

    ?>
    <script type=”text/javascript”>
    (function($) {

    jQuery(document).ready(function($) {
    var strNewString = $(‘.acf-relationship’).html().replace(/\Select taxonomy/g,’Filter Results’);
    $(‘.acf-relationship’).html(strNewString);
    });

    })(jQuery);
    </script>
    <?php

    }

    add_action(‘acf/input/admin_footer’, ‘my_acf_input_admin_footer’);

  • To get the category of the current post you need to do this using wp_get_post_terms() inside of your post loop.

    
    $terms = get_post_terms();
    

    This returns an array that you loop over to get the images for each term, https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

    
    foreach ($terms as $term) {
      $image = get_field('logo_image', $term);
    }
    
  • In order to show values in ACF from a category (term) you must supply the post ID where ACF will find the value.

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

  • Hey John, hopefully you can help me. I am working with ACF Theme Code Pro and the provided code I think works only on an archive page (?). I am just trying to output an image field put on my taxonomy in a WP_Query. Is the below code should be working considering that I need to replace “NULL” with something else? Thanks a lot!

    <?php 
    					
    // Acf Taxonomy Fields
    $taxonomy_prefix = 'category';
    $term_id = NULL;
    $term_id_prefixed = $taxonomy_prefix .'_'. $term_id;
    $image = get_field( 'logo_image', $term_id_prefixed );
    
    // args
    $args = array(
      'order'       => 'DESC',
      'orderby'     => 'date',
      'posts_per_page'	=> -1,
      'post_type'		=> 'post',
    );
    
    // query
    $posts_query = new WP_Query( $args );
    
    ?>
    <?php if( $posts_query->have_posts() ): ?>
      <?php while ( $posts_query->have_posts() ) : $posts_query->the_post(); ?>
      
      <div class="swiper-slide">
        <a href="<?php the_permalink(); ?>" class="c-card-article">
          <div class="c-card-article__img mb-15">
            <div class="c-card-article__overlay">
              <i class="icon-arrow-right"></i>
              <div><?php _e('Plus de détails', 'credo'); ?></div>
            </div>
    
            <?php if ( $image ) : ?>
              <img src="<?php echo esc_url( $image['url'] ); ?>" alt="<?php echo esc_attr( $image['alt'] ); ?>" class="c-card-article__cat">
            <?php endif; ?>
        
            <?php the_post_thumbnail( 'large', array( 'class' => 'u-w-100' ) ); ?>
          </div>
          <p><?php the_title(); ?></p>
        </a>
      </div>		
    
      <?php endwhile; ?>
    <?php endif; ?>
    
    <?php wp_reset_postdata(); ?>
  • I respond to myself.
    I added a taxonomy relational ACF field linked to my taxonomy.
    And it’s OK

  • Yes you are right ?>
    <script type=”text/javascript”>
    (function($) {

    jQuery(document).ready(function($) {
    var strNewString = $(‘.acf-relationship’).html().replace(/\Select taxonomy/g,’Filter Results’);
    $(‘.acf-relationship’).html(strNewString);
    });

    })(jQuery);
    </script>
    <?php

    }

  • I updated all instances of “select taxonomy” to “Filter Results” instead using the below jquery (add this to your functions.php):

    function my_acf_input_admin_footer() {
        
        ?>
        <script type="text/javascript">
        (function($) {
            
            jQuery(document).ready(function($) {
        var strNewString = $('.acf-relationship').html().replace(/\Select taxonomy/g,'Filter Results');
        $('.acf-relationship').html(strNewString);
    });
            
        })(jQuery); 
        </script>
        <?php
                
        }
        
        add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');
  • Edit – I ended up switching the company post type to a taxonomy as it seemed easier.

  • Based on the fact that this kind of feature exists as a pro add-on through ACF Extended, I assume it’s not something you can do natively in ACF. That page you liked also provides some instructions to target specific taxonomy terms with PHP.

  • Could you elaborate on why you created post-type-1 as a custom post type instead of a custom taxonomy? It might be easier to make a recommendation if we can understand your reasoning. Also, do you need the two post types to be associated with a taxonomy or could you simply use an ACF relationship field to associate them?

  • Hi midwestdev,

    Thaks for providing your version of the code.

    Any further, and you’d need to add more to the JS and to the PHP to make this cascade into grandchildren, etc.

    Can you provide and example of PHP and JS where the cascade has been extended up to 4 levels.

    I also noted that after updating the post the values in the select fields only show the parent value.

    However when you convert the ACF fields from SELECT back to checkboxes the correct values have been saved.

    So I think some additional JS is require on POST EDIT to re-populate the ACF taxonomy.

    Did you solve this?

  • Thanks for the screenshots, that makes it much clearer what you’re trying to do.

    My assumption about why this might not be working for you is that that dynamic content setting is probably looking for that ACF field on the current product since you’ve created a product loop. But that feels doesn’t exist alongside products, it exists alongside a taxonomy term that happens to be applied to that product, so Elementor doesn’t know where to look to find that field data. I could be wrong; like I said I don’t have experience with Elementor Custom Skin to know exactly how it works in this scenario.

    This is why I’m thinking that L&L might be a solution that could work for you if you’re comfortable displaying your image by writing a line or two of HTML instead of using Elementor’s editor. The markup I shared above could be placed inside an L&L template and then that template could be run within your loop using either a shortcode or the built-in Elementor widget. Essentially what it’s doing is saying “hey WordPress, look through the taxonomy terms associated with the current post/product in the brand taxonomy and then for each term that’s applied to this post, get me the logo image field for that taxonomy term.” Considering the actual field/taxonomy names you showed in your screenshot, that might look something like this in your case:

    
    <Loop taxonomy=brand post=current>
      <img src="{Field acf_image=logo field=url}" />
    </Loop>
    

    Can’t help you much beyond that, but there’s a good chance that this template above will just work out of the box if you place it inside your loop using any of the methods I linked above. I hope that’s helpful for you, let me know how this goes!

  • Hi bentangible!

    Thanks for the fast reply! Yes i made a custom product loop skin for my site. Maybe i should be more specific about the thing i want to achieve with ACF.

    So as default woocommerce has a thumbnail upload option for the core Categories taxonomy, but not for tags or custom taxonomies: Image

    This image can be pulled dynamically by elementor under the Dynmic tags-> Woocommerce-> Category Image as shown: Image

    I want to replicate this dynamic image function from woocommerce, so i created a custom taxonomy for brands, to display the brand logo on the frontend. With ACF i added an image upload field for the taxonomy: Image

    So right now i am able to upload an image for each brand in the taxonomy, and i can select the image field in elementor: Image

    But after i select the acf image field, the logo doesnt show up on the frontend.

    Im a bit confused, maybe im missing some code that outputs this image field on the front end.

  • I’m not super familiar with Elementor Custom Skin but it sounds like you’ve made a product loop, but your ACF image field is located on a taxonomy term which means that the image itself isn’t accessible from the product loop and you’d instead need a taxonomy term loop to get that data. I wish I could tell you exactly how to do this with Elementor Custom Skin but I tend to use Loops & Logic for this kind of thing. You could add a Tangible Template widget within your product loop and write something like this to make that work:

    
    <Loop taxonomy=your_custom_taxonomy_name post=current>
      <img src="{Field acf_image=your_image_field_name field=url}" />
    </Loop>
    
  • Update (in case anyone is still around for this): this still happens on the latest version, but NOT when the condition is, for example, “post type is equal to post”, but it does when the condition is category or taxonomy. I hope someone has a fix for this.

  • You need to add a tax_query as explained in the WP_Query() docs.

  • You are correct. You cannot limit where individual fields are shown, only entire field groups.

    It is possible to limit where a specific field is used by using an acf/prepare_field filter to remove fields that should not be shown. You would need to use the “field key” variant of the filter and you would need to determine for yourself when the field should be shown or not.

    In all likely hood it would mean saving the post to become effective. For example, if a location rule is based on a taxonomy term then the post would need to be saved with that taxonomy term before you would be able to test for that taxonomy in your filter function. The same would apply to any setting that is generally controlled by WP.

    This could be overcome by moving all WP settings into custom fields, you could then use conditional logic based on these new custom fields instead of the above filter. However, this would mean creating an acf/save_post action to convert all of the new controls into WP setting when the post is saved. This may also not be possible in all cases.

  • Solved. just used get_terms with arguments: the taxonomy and the custom field.

  • Make a new taxonomy picker field with another name for example subject_picker and adapt your logic if subject_picker field has a value do new logic if not do old logic.

    and also maybe create terms by the old text inputs with a job. (looping all your posts, getting the field and creating term (wp_insert_term()).

    then do a job and set value to all the old terms for the new subject_picker field.

  • Thank you for the code. I plugged that in and made changes as necessary and got it to work except listing the titles. It is listing the current page titles over and over instead of from the relationship field.

    Do you know where I might have gone wrong?

    $avail_services = get_field( 'related_services', false, false );
    	if ( $avail_services ) {
    		$types = get_terms( array(
    			'taxonomy' => 'service_type',
    			'hide_empty' => true,
    			'object_ids' => $avail_services
    			)
    		);
    		foreach( $types as $type ) {
    			$args = array(
    				'post_type'         => 'services',
    				'posts_per_page'    => -1,
    				'post__in'          => $avail_services,
    				'orderby'           => 'post__in',
    				'tax_query' => array(
    					array(
    					'taxonomy' => 'service_type',
    					'terms' => $type->slug,
    					'field' => 'slug',
    					),
    				),
    			);
    			$svc = new WP_Query($args);
    			echo '<h2>'.$type->name.'</h2>';
    			echo '<ul class="sidebar-menu">';
    			foreach( $svc->posts as $post ) { setup_postdata( $post );
    				echo '<li>'.get_the_title().'</li>';
    			};
    			wp_reset_postdata();
    			echo '</ul>';
    		};
    	};
  • Thank you for this code! It has helped with categorization, however, I am having an issue. It is not listing the correct titles under each category. Instead it’s categorizing from the relationship field but when I do the_title(); it is repeating the curent page’s title.

    Custom post types named solutions and services. Services has taxonomy service_type attached.

    In solutions, I have created a relationship field called related_services.

    Below code is in the template for solutions page. Any idea what I might be doing wrong?

    <?php
    $avail_services = get_field( 'related_services', false, false );
    
    if ( $avail_services ) :
    	$types = get_terms( array(
    		'taxonomy' => 'service_type',
    		'hide_empty' => true,
    		'object_ids' => $avail_services
    		)
    	);
    
    	foreach( $types as $type ) :
    		$args = array(
    			'post_type'         => 'services',
    			'posts_per_page'    => -1,
    			'post__in'          => $avail_services,
    			'orderby'           => 'post__in',
    			'tax_query' => array(
    				array(
    				'taxonomy' => 'service_type',
    				'terms' => $type->slug,
    				'field' => 'slug',
    				),
    			),
    		);
    		$svc = new WP_Query($args); ?>
    		<p class="widget-title service_types"><?php echo $type->name; ?></p>
    		<ul class="sidebar-menu">
    		<?php foreach( $svc->posts as $post ) : setup_postdata( $post ); ?>
    			<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    		<?php endforeach; wp_reset_postdata(); ?>
    		</ul>
    	<?php endforeach; ?>
    <?php endif; ?>
  • Super-late response, but for anyone else checking here: I had this exact same requirement, and someone else has made a plugin for it:

    https://wordpress.org/plugins/acf-multiple-taxonomy/

    This just adds another ACF field type called Multiple Taxonomies and works pretty much exactly how you’d expect.

  • Hello @hube2
    Ok, oh yes I understand.
    I tried with “date_clause” and unfortunately it’s still the same…
    Here is the updated code :

    
    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_clause' => array(
            'key' => 'date_de_sortie',
            'compare' => 'EXISTS',
            )
          )
        );
        $query->set( 'orderby', array(
          'date_clause' => 'ASC',
          'title'   => 'ASC',
          )
        );
      }
    }
    
  • Here is the new code with meta_query, but same result.
    Any idea on what I’m missing ?

    
    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',
          )
        );
      }
    }
    
  • Here is the new code with meta_query but same results.
    There is something I don’t understand…

    
    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',
      )
    );
    }
    }
    
Viewing 25 results - 776 through 800 (of 3,193 total)