Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

reply

  • That worked, in case this helps somebody else:

    if ( is_product_category() ) {
    		// vars
    		$queried_object = get_queried_object(); 
    		$taxonomy = $queried_object->taxonomy;
    		$term_id = $queried_object->term_id;  
    		$foto = get_field( 'foto', $queried_object );
    		$foto = get_field( 'foto', $taxonomy . '_' . $term_id );
    		if( get_field('foto', $taxonomy . '_' . $term_id) ) {
    			echo '<div class="cat-banner"><img src="' . $foto . '"/></div>';
    		}
    	}
  • I was looking for this exact answer! Thanks! However, I need to output the svg for each term in a taxonomy loop. When it comes to that, ACF requires the term variable to be passed on as a second parameter in get_field().

    So I tried this:

    <?php $svgImg = get_field('my_custom_field', $term, 'option'); ?>
    <?php echo file_get_contents( $svgImg ); ?>

    But I get this php error:

    “Warning: “file_get_contents() expects parameter 1 to be a valid path”

    Seems like it´s not an issue related to the order of the parameters as when I swap $term and option, it makes WP blind to what term I´m referring to:

    “Warning: file_get_contents(): Filename cannot be empty”

    $term has been properly defined as I have tested it with:

    <?php $svgImg = get_field('my_custom_field', $term); ?>
    <img src="<?php echo $svgImg['url']? />">

    This last piece of code works. But the previous doesn´t.

    Can somebody help?

  • actually, what you have in your code here, either of them, should work if the image is added to the category.

    
    $foto = get_field( 'foto', $queried_object );
    $foto = get_field( 'foto', $taxonomy . '_' . $term_id );
    

    but this will be false since it’s not using one of the two values for post ID from above

    
    if( get_field('foto') ) {
    

    pick one of the first two and use it for all acf calls

  • Ordering terms in WP is tough. For the moment I’ve gone with the solid plugin,
    Custom Taxonomy Order NE. If I have time, I’ll likely pursue something along the lines of what you’ve laid out and update this post with progress and potential workaround for others.

    But if you can order your taxonomy with the above plugin it allows you inefficiently get an archive of posts by tax term. You can create a series of WP_Query calls that run through each term. Use get_terms() to create an array of all tax terms, then run a foreach over each term. This creates a WP_Query for each term item that will return all posts for a given term. Code to make this happen:

      // Get your terms and put them into an array
      $issue_terms = get_terms([
        'taxonomy' => 'issues',
        'hide_empty' => false,
      ]);
    
      // Run foreach over each term to setup query and display for posts
      foreach ($issue_terms as $issue_term) {
        $the_query = new WP_Query( array(
          'post_type' => 'post',
          'tax_query' => array(
            array(
              'taxonomy' => 'issues',
              'field' => 'slug',
              'terms' => array( $issue_term->slug ),
              'operator' => 'IN'
            )
          )
        ) );
    
        // Run loop over each query
        while($the_query->have_posts()) :
          $the_query->the_post();
    
          // YOUR TEMPLATE OUTPUT FOR EACH POST
    
        endwhile;
      }
  • The code is located on the file “content.php” of the theme Stargazer. I can’t found a standard function. The complete code is presented bellow:

    <article <?php hybrid_attr( 'post' ); ?>>
    
    	<?php if ( is_singular( get_post_type() ) ) : // If viewing a single post. ?>
    
    		<header class="entry-header">
    
    			<h1 <?php hybrid_attr( 'entry-title' ); ?>><?php single_post_title(); ?></h1>
    
    			<div class="entry-byline">
    				<span <?php hybrid_attr( 'entry-author' ); ?>><?php the_author_posts_link(); ?></span>
    				<time <?php hybrid_attr( 'entry-published' ); ?>><?php echo get_the_date(); ?></time>
    				<?php comments_popup_link( number_format_i18n( 0 ), number_format_i18n( 1 ), '%', 'comments-link', '' ); ?>
    				<?php if ( function_exists( 'ev_post_views' ) ) ev_post_views( array( 'text' => '%s' ) ); ?>
    				<?php edit_post_link(); ?>
    			</div><!-- .entry-byline -->
    
    <!-- MOSTRAR CAMPOS PERSONALIZADOS -->
    
    	<!-- Documento principal -->
    
    		<?php
    	$attachment_id = get_field('archivo');
    	$url = wp_get_attachment_url($attachment_id);
    	$title = get_the_title($attachment_id);
    	$path_info = pathinfo(get_attached_file($attachment_id));
    	$filesize = filesize( get_attached_file( $attachment_id ) );
    	$filesize = size_format($filesize, 2);
    
    		if(get_field('archivo')): ?>
    			<div class="titulos_secundarios">Ver documento:</div><br/><br/>
    			<a href="<?php echo $url; ?>" target="_blank" title="Abrir documento en una nueva pestaña" style="display: inline;"><?php echo $title?>.<?php echo $path_info['extension'];?> (<?php echo $filesize; ?>)</a>
    		<?php 
    		endif; 
    ?>
    	<!-- Documentos secundarios -->
    
    		<br/>
    		<div class="titulos_secundarios">Antecedentes</div>
    		<br/>
    
    <?php if(have_rows('otros_archivos')):
    	while (have_rows('otros_archivos')) : the_row();
    	$post_object = get_sub_field('antecedente');
    		echo "<ol>";
    		if($post_object): 
    			$post = $post_object; setup_postdata($post); ?>
    			<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    		<?php wp_reset_postdata();
    		else:
    			echo "<li>No se ha incluido ningún antecedente aún.</li><br/>";
    		endif;
    	echo "</ol>";
    	endwhile;
    endif; ?>
    <!-- FIN MOSTRAR CAMPOS PERSONALIZADOS -->
    
    		</header><!-- .entry-header -->
    
    		<div <?php hybrid_attr( 'entry-content' ); ?>>
    			<?php the_content(); ?>
    			<?php wp_link_pages(); ?>
    		</div><!-- .entry-content -->
    
    		<footer class="entry-footer">
    			<?php hybrid_post_terms( array( 'taxonomy' => 'category', 'text' => __( 'Posted in %s', 'stargazer' ) ) ); ?>
    			<?php hybrid_post_terms( array( 'taxonomy' => 'post_tag', 'text' => __( 'Tagged %s', 'stargazer' ), 'before' => '<br />' ) ); ?>
    		</footer><!-- .entry-footer -->
    
    	<?php else : // If not viewing a single post. ?>
    
    		<?php get_the_image( array( 'size' => 'stargazer-full', 'order' => array( 'featured', 'attachment' ) ) ); ?>
    
    		<header class="entry-header">
    
    			<?php the_title( '<h2 ' . hybrid_get_attr( 'entry-title' ) . '><a href="' . get_permalink() . '" rel="bookmark" itemprop="url">', '</a></h2>' ); ?>
    
    			<div class="entry-byline">
    				<span <?php hybrid_attr( 'entry-author' ); ?>><?php the_author_posts_link(); ?></span>
    				<time <?php hybrid_attr( 'entry-published' ); ?>><?php echo get_the_date(); ?></time>
    				<?php comments_popup_link( number_format_i18n( 0 ), number_format_i18n( 1 ), '%', 'comments-link', '' ); ?>
    				<?php edit_post_link(); ?>
    			</div><!-- .entry-byline -->
    
    		</header><!-- .entry-header -->
    
    		<div <?php hybrid_attr( 'entry-summary' ); ?>>
    			<?php the_excerpt(); ?>
    		</div><!-- .entry-summary -->
    
    	<?php endif; // End single post check. ?>
    
    </article><!-- .entry -->
  • Hi @artisancodeur

    You can get the value from ACF fields assigned to Taxonomies by passing the term as a second parameter to the get_field() function.

    Please take a look at the following resource page: https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/

  • Scenario 1

    If I’m understanding correctly, no, you cannot do this. You want to reorder the “terms” in a taxonomy based on a date edited when adding a “post”. You can’t order the terms according to something associated with the posts in those terms. To do this you would need to build something custom to somehow record the most recent date of all of the posts in a term and store that information in a way that is related to the term so that you can then use the date added to the term to order the terms.

    1. acf/save_post priority > 10 https://www.advancedcustomfields.com/resources/acf-save_post/
    2. get the term of the post being saved
    3. get the post in the term with the most recent date
    4. update the term using term meta with this date https://codex.wordpress.org/Function_Reference/update_term_meta
    5. add a meta_query to your get terms call to sort them by this new term meta key

    Scenario 2

    You already have most of this, you just need to add a meta_key and order by the meta key in your query. https://www.advancedcustomfields.com/resources/orde-posts-by-custom-fields/

  • From the looks of things you are only returning the term ID, it’s one of the settings for a taxonomy field. To get the other information you need to set the return value to Term Object. This may alter how you call some of the other functions because you’ll get the entire object rather than just the ID

  • What version of ACF are you using?

    
    // ACF >= 5.5.0
    $queried_object = get_queried_object(); // gets the term
    $post_id = 'term_'.$queried_object->term_id;
    $image = get_field('image_field_name', $post_id);
    
    
    // ACF < 5.5.0 - will also work on >= 5.5.0
    $queried_object = get_queried_object(); // gets the term
    $post_id = $queried_object->taxonomy.'_'.$queried_object->term_id;
    $image = get_field('image_field_name', $post_id);
    

    for more information see the section on getting field values from different objects on this page https://www.advancedcustomfields.com/resources/get_field/

  • function change_order_for_events( $query ) {
        //only show future events and events in the last 24hours
        $yesterday = date('Ymd');
    
        if ( $query->is_main_query() && (is_tax('dt_portfolio_category') || is_post_type_archive('dt_portfolio')) ) {
            $query->set( 'meta_key', 'sub_seminars_0_start_date' );
            $query->set( 'orderby', 'meta_value_num' );
            $query->set( 'order', 'ASC' );
    
            //Get events after 24 hours ago
            $query->set( 'meta_value', $yesterday );
            $query->set( 'meta_compare', '>' );
    
           //Get events before now
           //$query->set( 'meta_value', current_time('timestamp') );
           //$query->set( 'meta_compare', '<' );
        }
    
    }
    
    add_action( 'pre_get_posts', 'change_order_for_events' );

    this code in function.php will sort your posts based on a specific meta key value.
    sub_seminars_0_start_date

    I have created a custom taxonomy Seminar Venues but the above code won’t work for that even after adjustin the parameters.

  • Rather than create a custom field type, use a select field and create a format value filter for the field to return the same thing that ACF returns for a taxonomy field. This would let you change the field type without altering any of the code where the current field is used and let you keep using it the same way. https://www.advancedcustomfields.com/resources/acfformat_value/ Probably a lot less coding than either of the other choices?

  • I could dynamically load a select field, but unfortunately I’m already using some of the specific taxonomy field features in multiple places in my code (e.g. saving tax terms, using get_field to get full term object etc) so it would involve a fair bit of refactoring.

    Support suggested the same thing, or that I could create my own field type which would mean I don’t need to refactor any existing code.

    Either way looks like solving this will involve a fair bit of (re)coding 🙁 but at least I’m not missing something obvious.

    Thanks for your help.

  • HI @teddy

    You would need to modify the posts_per_page argument on the field type.

    This can be achieved through the use of the acf/fields/taxonomy/query.

    Please check out the usage of this filter here: https://www.advancedcustomfields.com/resources/acffieldstaxonomyquery/

  • The problem here is that there isn’t anyone that is familiar enough with WC or WC templates. What you need to do is find out from WC or from someone that knows enough about WC to get the taxonomy and term. I personally have not worked with WC so can not really help you much with this.

    You’re using 2 different plugins here and for the most part you’re only going to find help with the ACF part of it here. I’m willing to help you figure out how to show the values of your fields if you do the legwork to figure out how to get the term in the template where you are modifying code, or how to get the term inside of the WC filter that you need to use to add your custom code.

    Please also note that this is only for ACF4 now. ACF5 Pro (5.5.0) has implemented term meta which means that you and use either the "{$taxonomy}_{%term_id}" method or your can now use "term_{$term_id}"

    As far as the odd output of the contents of a field, please see the example code provide in the documentation section of this site. Most field types except the basic field types, need you do to more than echo their values depending on what you have them set to return.

  • Hi, I spent many hours whit this issue and I can’t find a solution.
    As I see there are more people trying to deal with that.

    The problem is that the proposed solution of using:

    $grade = get_field('grade', $taxonomy . '_' . $term_id);

    is not working in our case.

    I’m also trying to use the code above passing the data as string but the retrieved value is ever NULL.

    $title = get_field('my_title', 'dc_vendor_shop_5');

    I’m using ACF with Woocommerce and wc-marketplace.com Multivendor plugin

    Could someone help with this issue?

    Thanks.

  • what version of ACF are you using? It should be picking them up and showing them under Post Taxonomy.

    There is a way you can avoid re-selecting the same tags, but it will require saving the post twice.

    You can dynamically set the choices of a checkbox field the same way that is described here https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/. But like I said, for this to work you’d have to save the post and then on the second load you’d see values.

    In the filter you would get the tags associated with the current post and populate the choices array.

  • I tried using a taxonomy field from ACF, but it wasn’t picking up my taxonomy as an option from the Custom Post Type that this post is. Is there a way to get taxonomies from Custom Post Types?

    Also, if I’m understanding your suggestion correctly, I’d have to add the tags twice: to the full list field, and to the publicly-displayed field. I was hoping to avoid that redundancy by having the ACF field reference the list of tags already assigned to the post.

  • I would probably use an ACF field stored as part of the post rather than my own custom field in a widget. I’d probably also remove or hide the standard WP tag box and add that as a custom field as well. Both of these fields would be taxonomy field for tags. One of the fields would save and load terms while the other does not. Then when you work on the front end I’d use the values saved in the one that does not save and load terms to do my displaying of tags.

    The main reason that I use ACF is to avoid custom coding custom fields in the WP admin.

  • Yep — I mean the normal WP tags taxonomy. Here’s how it looks within the admin:

    https://cl.ly/2F0f0k2U3m42

    You can see the normal tag list on the top, then my component with checkboxes below. You’ll see that I unchecked “Plants 101” and “Relaxation Line”, so that (once it’s working) those wouldn’t be displayed on the front end.

    I’m just not sure how to save that because those tags are being generated automatically using the following code:

    $post_id = $_GET['post'];
    $tags = wp_get_post_tags($post_id);
    foreach($tags as $tag) {
        echo '<input type="checkbox" name="ppjtags_'. $tag->term_id .'" checked>'. $tag->name .'<br>';
    }

    Does that help clarify things?

  • You’re going to need to tell me how the tags are generated in the first place, but my initial reaction is

    you have an options page with a field where these tags are selected, that saves the values. Then on the post edit page you use these values to filter what is shown in the same type of field for posts.

    Like I said, just a very rough idea, it would depend what the “tags” are (do you mean the WP tags taxonomy?) and how these values are dynamically generated?

  • Hey guys,

    I’m having the same problem as @iamrobertandrews. I have a User register form in which I have some taxonomies, and I use those taxonomy terms checked by user for filtering users in a page.

    I have a ACF User form, and on this form I have these taxonomy related fields. Then, I’m using LH User Taxonomy plugin for having a User Taxonomy UI and also to have this working.

    All things was working fine until 03/03/2017 (user was registering, then taxonomy field terms was populating User Taxonomies correctly, automatically). But, for some reason it stopped to work on 03/03/2017 (date of last user register that recorded taxonomies correctly).

    The weird thing, I did the @iamrobertandrews experiment, which means, getting a registered user that comes with blank taxonomy feilds, then I checked some terms manually on User Edit page, and then saved. For some reason, it worked! Buuuuuut, I need this working from the form, because I can’t know what item the user filled if it comes blank…

    So, I was wondering if you guys have any idea about why it was working and from 03/03 it isn’t anymore? Where should I look for a bug (something that I changed and make it stop to work), or if you have any suggestion for getting it working again.

    Thanks in advance.

    Cheers.

    ACF version 5.5.11

    Form: http://www.cieb.net.br/cadastro-pessoa-fisica/

    Form WP Page:

    <?php
    acf_form_head();
    get_header();
    ?>
    
    	<!-- #Content -->
    	<div id="Content">
    		<div class="content_wrapper clearfix">
    	
    			<!-- .sections_group -->
    			<div class="sections_group">
    
                	<div class="container">
                    	<div class="row form-cadastro-especialista">
    				<?php if ( have_posts() ) : ?>
                        <div class="col-xs-12"> 
                                    <?php while ( have_posts() ) : the_post(); ?>
    
                                         </div>
     
                                          <form action="<?php echo site_url('wp-login.php?action=register&role=especialista', 'login_post') ?>" method="post">
                                          	<div class="acf-field">
                                                <div class="acf-label">
                                                  <label><span class="numero-questao">1</span>Nome de Usuário (login)</label>
                                                </div>
                                                <div class="acf-input">
                                                <div class="acf-input-wrap">
                                                  <input type="text" name="user_login" value="Nome de Usuário" id="user_login" class="input" />
                                                  </div>
                                                  <p class="description">Seu nome de usuário (login) poderá ser utilizado futuramente para que você utilize outros serviços da Rede IEB.</p>
                                                </div>
                                              </div>
                                              <div class="acf-field">
                                                <div class="acf-label">
                                                	<label><span class="numero-questao">2</span>Seu E-mail</label>
                                                </div>
                                              <div class="acf-input">
                                                <div class="acf-input-wrap">
                                            
                                                <input type="text" name="user_email" value="E-Mail" id="user_email" class="input"  />
                                                </div>
                                                <p class="description">Você receberá em seu e-mail um link para cadastrar sua senha.</p>
                                              </div>
                                             </div>
                                              <?php do_action('register_form'); ?>
                                              <input type="submit" value="Cadastrar" id="register" />
                                              <input type="hidden" name="redirect_to" value="/solicitacao-cadastro-pessoa-fisica"/>
                                          </form>
                                            
                                    <?php endwhile; ?>
                                
                            <?php else : ?>
                                <p><?php _e( 'Desculpe, não há conteúdo disponível para esta página ainda. Volte em breve.', 'cieb' ); ?></p>
                            <?php endif; ?>
                            </div>
    					</div><!--row-->
                        
    				</div><!--container-->
                </div><!--sections_group-->
    	
    		</div><!--content_wrapper-->
    	</div><!--#Content-->
    	
    	<?php get_footer();?>
  • Hi

    i have tried to show an image and text block on woocommerce category page . I have tried almost every example .

    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;

    $grade = get_field(‘grade’, $queried_object);
    $grade = get_field(‘grade’, $taxonomy . ‘_’ . $term_id);

    this code will showing me only the following output

    6395, , category-ballons, , , image/png, https://i2.wp.com/kxxxxxx.com/demo/wp-content/uploads/2016/09/category-ballons.png?fit=1920%2C400, 1920, 400, Array

    any of the solution didn’t works for me .

  • Another clue:

    var_dump(get_fields($term_object->term_id));

    Returns:

    /srv/www/soux-calvo.dev/current/web/app/themes/sc/taxonomy-p‌​ersonas.php:10:boole‌​an false

  • Then you’ll also need to add a tax query to your query. See the WP_Query() doc https://codex.wordpress.org/Class_Reference/WP_Query

    I can’t say how you’ll need to incorporate this, but it will involve figuring out what taxonomy/term WP is already using.

    Either that or there’s some debugging you’ll need to do in what I’ve provided. The code I provided was not tested, it was put together based on the information you’ve given.

  • Like I said, WordPress create URLs for each of the terms in the taxonomy. These pages automatically only show the posts for a specific term.

    What you are doing here is overriding the query that WP has already done

    
    $posts = get_posts(array(
    	'post_type'			=> 'dt_portfolio',
    	'posts_per_page'	        => -1,
    	'meta_key'			=> 'sub_seminars_0_start_date',
    	'orderby'			=> 'meta_value',
    	'order'				=> 'ASC'
    ));
    

    You either need to add a taxonomy query to this in order to recreate what WP is already doing… this is a waste, will take more work, and will slow down your site because you’re doing multiple queries when they are not needed….

    … or you can set up a pre_get_posts filter https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts to add the new sort order to the query that WP is already performing.

    
    
    	
    // add to functions.php	
    function order_dt_portfolio_by_repeater($query=false) {
    	
    	// only used on main query on front end of site
    	if (is_admin() || !$query || !is_a($query, 'WP_Query') ||
    		!$query->is_main_query()) {
    		return;
    	}
    	
    	// modfiy a custom post type to show and order by meta value
    	if (isset($query->query_vars['post_type']) &&
    			$query->query_vars['post_type'] == 'dt_portfolio') {
    		$query->set('meta_key', 'sub_seminars_0_start_date');
    		$query->set('orderby', 'meta_value');
    		$query->set('order', 'ASC');
    		$query->set('posts_per_page', -1);
    	}
    } // end function blunt_pre_get_posts
    add_action('pre_get_posts', 'order_dt_portfolio_by_repeater');
    
Viewing 25 results - 1,801 through 1,825 (of 3,193 total)