Support

Account

Home Forums General Issues some problem with acf taxonomy

Solving

some problem with acf taxonomy

  • Hi. I have some problem with acf taxonomy.
    I need to get info in my sidebar block from acf checkbox taxonomy fueld.
    Code examples – Basic display (multiple values) – (https://www.advancedcustomfields.com/resources/taxonomy/) – don`t get any info and write me only – View all ” posts – url from cheked taxonomy in page.

    PHP knowledge is very low but it is very necessary to solve this problem πŸ™
    I will be glad to any help.

    What should be done in the final version:
    – taxanomy title
    — post title + url
    — post title + url
    — post title + url

    – taxanomy title
    — post title + url
    ….

    Some scrin
    http://joxi.ru/eAOY5Jqt4eX4em
    http://joxi.ru/KAgoEyKug0dglA

  • Hi @konstantin

    Could you please tell me the location rule of the field group? Was it the post, page, taxonomy, or anything else?

    Basically, if you call a custom field outside The Loop, you need to provide the ID of the object where you set the location rule. So, if you set the rule to a post, you need to do it like this:

    $terms = get_field('taxonomy_field_name', 99);

    Where “99” is the ID of the post. If set the location rule to taxonomy, it has different ID structure. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/.

    I hope this helps πŸ™‚

  • Hi @james
    Thanks for your quick answer and a desire to help.
    I will try to explain the problem as detailed as possible.

    1. For example – I get custom field “eee”, which should display multiple taxonomy (checkbox) – from parent taxonomy “trip”.
    http://joxi.ru/52azJO1IGY1gPA

    2. “trip” taxonomy structure in screen:
    http://joxi.ru/ZrJYE1Vt1y4QoA

    3. Field view in page:
    http://joxi.ru/ZrJYE1Vt1y4koA

    In final variant I need to display selected taxonomy and link to the page included in this taxonomy.
    Example:
    – title of selected taxonomy
    — post title + url
    — post title + url

    – title of selected taxonomy
    — post title + url
    — post title + url

    When I try to use this code:

    <?php 
    $terms = get_field('eee');
    if( $terms ): ?>
    	<ul>
    	<?php foreach( $terms as $term ): ?>
    		<h2><?php echo $term->name; ?></h2>
    		<p><?php echo $term->description; ?></p>
    		<a href="<?php echo get_term_link( $term ); ?>">View all '<?php echo $term->name; ?>' posts</a>
    	<?php endforeach; ?>
    	</ul>
    <?php endif; ?>

    It does`t give me any values only included taxonomies links (http://joxi.ru/V2VLGlnf0OjaLr) – in castom field I checked 2 taxonomy.

    Can`t use ID, because taxonomy not bind to specific pages.

  • Hi everyone. Maybe someone faced a similar problem? Need to find the solution … I have read a lot of things, but could not find the right…

    I would be glad for any help!

  • Hi @konstantin

    Could you please share the screenshot of the field group’s location rule? Did you mean you want to show all pages that have the taxonomy custom field selected on it? If you did, then you need to query the pages for each term returned by the custom field. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/. Here’s an example how to do it:

    <?php 
    $terms = get_field('eee');
    if( $terms ): ?>
    	<ul>
    	<?php foreach( $terms as $term ): ?>
    		<a href="<?php echo get_term_link( $term ); ?>">View all '<?php echo $term->name; ?>' posts</a>
            <?php
            $posts = get_posts(array(
                'numberposts'	=> -1,
                'post_type'		=> 'page',
                'meta_query'	=> array(
                    array(
                        'key'	 	=> 'eee',
                        'value'	  	=> '"' . $term->term_id . '"',
                        'compare' 	=> 'LIKE',
                    ),
                ),
            ));
            ?>
            
            <?php foreach( $posts as $post ): 
    		
                setup_postdata( $post )
                
                ?>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            
            <?php endforeach; ?>
            
    	<?php endforeach; ?>
    	</ul>
    <?php endif; ?>

    I hope this helps πŸ™‚

  • Hi James. Thank you for your efforts and time!
    I will try as much as possible right now to describe the problem.

    1. I need to get this taxonomy for the site of the tourist agency.
    That is a have some structure:

    Europe
    – coutnry (with types of recreation )
    — citys (with hotel inside)
    — hotel

    Screen of what the result should turn out (example country – Austrya):
    http://joxi.ru/a2XZ76VSy9NeQr
    This country have several kinds of recreation (spa, ski and other)
    I need to get selected taxonomy title – with the title and URL of the pages included in the taxonomy.

    {taxonomy title}
    – {page title + url}
    – {page title + url}
    – {page title + url}

    {taxonomy title}
    – {page title + url}
    – {page title + url}
    – {page title + url}

    2. Screenshot of the field group’s location rule
    http://joxi.ru/KAgoEyKug0owZA

    3. Tried to run your code:
    http://joxi.ru/823xgJOI6pZPkA

    4. Block in page
    http://joxi.ru/a2XZ76VSy9xw9r

    5. Structure of taxonomy
    http://joxi.ru/EA4zaqNIDkdpGm
    Structure makes for ease of operation when selecting taxonomies

    Thank you very much for your help!!!

  • Hi @konstantin

    Thank you very much for the detailed explanation. That sure helped a lot πŸ™‚

    It seems that the issue here is that the field can’t show the terms title. It returns the correct amount, though.

    Could you please check the $terms value like this:

    <?php 
    $terms = get_field('eee');
    var_dump($terms);
    ?>

    Thanks πŸ™‚

  • Hi @konstantin

    I get it now. It seems that you set the taxonomy field’s “Return Value” to “Term ID”. Kindly change it to “Term Object” and see if it fixes the issue. I’ve attached a screenshot for your reference.

    Thanks πŸ™‚

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.