Skip Navigation

[Resolved] Taxonomy glitch

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 24 replies, has 2 voices.

Last updated by Beda 6 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#614903
This is neither WP nor toolset.png

This can be, but it's not Toolset doing this.

You can look it up in the documentation shared, but also in the code, in the Views plugin, in the file /embedded/inc/wpv-shortcodes.php in the wpv_post_taxonomies_shortcode_render() function.
The allowed attributes are:

if ( $order == 'asc' ) {
  ksort( $out_terms );
} elseif ( $order == 'desc' ) {
  ksort( $out_terms );
  $out_terms = array_reverse( $out_terms );
}

There is definitely a software or Custom code in place to alter the terms.
I attached a screenshot of what I mean. This cannot be achieved with WordPress and Toolset alone.

Maybe it's the theme adding this? It's not there, in a WordPress/Toolset install, and the posts seem to match (the failing posts have those taxonomy set)

As I debugged this issue, and the issue is gone when you have no other plugins, and resale the post.

I am not sure how this has been setup, but it seems the root of this problem.

We need to know what adds that code, then disable this and revert the changes it made, as it obviously alters the WP Query.

#614906

I also see that your parent theme uses code, where for example the taxonomy we deal with is mentioned:

penci_get_the_term_list( get_the_ID(), 'viagens' );

Are you sure this taxonomy has been setup with Toolset Types?
If so, why is the Term created with Types present in the parent Theme?

Has this theme been created exactly with the current setup in mind?

It could be that this Taxonomy was delivered by the theme instead, and then, it could be that controlling it with Types will not work.

#614907

Are you sure this taxonomy has been setup with Toolset Types? "Yes, absolutely."

"If so, why is the Term created with Types present in the parent Theme?"

That was done, so that the theme could display the custom taxonomy in line with the native categories in the breadcrumbs

So you think this could affecting the taxonomy hierarchy?

Thanks.

#614908

It seems that Primary and Make Primary is added by Yoast:

hidden link

But I don't see how that could be affecting the hierarchy. Because even if I disable Yoast (and primary disappears from the custom taxonomy checklist) the issue remains and the taxonomy is displayed in the wrong order.

#614916

And it's all also here. So, the primary is just a Yoast thing, but it's causing the issue I don't think. Because even with Yoast disabled that doesn't work.

https://toolset.com/forums/topic/what-means-make-primary-in-taxonomy/

#614976
screenshot4.png
screenshot2.png
screenshot1.png
screenshot3.png
wrong order post page.png

Hi Beda,

So, an update. I was searching for the what could be causing this and it seems it's Types causing the issue.

Following the instructions here:

https://toolset.com/forums/topic/display-wpv-post-taxonomy-and-hierarchical-taxonomies/
https://toolset.com/forums/topic/taxonomy-order-2/

I did the following:

I added this code to the theme-child functions.php

// taxonomy order by hierarchy

function list_hierarchical_terms($atts) {
    global $post;
     
     
    $taxonomy = $atts['taxonomy']; // change this to your taxonomy
    $separator = $atts['separator'];
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
    if( $terms ) {
        $terms = trim( implode( ',', (array) $terms ), ' ,' );
        return wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms."&hierarchical=1"."&separator=".$separator."&echo=0&style=none");
         
    }
}
add_shortcode('display_post_tax_terms_hierarchical', 'list_hierarchical_terms');

Then I replaced the short code I had

<div class="grid-header-box">
                           <span class="cat penci-cat-name">[wpv-post-taxonomy type="category" separator=""][wpv-post-taxonomy type="viagens" order="parent" separator="  "]</span>

with this:

<span class="cat penci-cat-name">[wpv-post-taxonomy type="category" separator=""] [display_post_tax_terms_hierarchical taxonomy="viagens" separator="  "]
</span> 

the diference is this

[display_post_tax_terms_hierarchical taxonomy="viagens" separator="  "] 

This was done following the instructions from the posts above moderated by Minesh.

After doing this I got the following results:

Taxonomy is working fine for all terms in:

homepage (including for Oceânia) (screenshot 1 and 2)
archive page (including for Oceânia) (same as the homepage)
content template (including for Oceânia) (screenshot 3)

However, it's not working on the post pages ONLY for the term Oceânia. All the other terms are fine, including in the post pages. (screenshot named wrong order post page)

Then, I created a new parent term named "Category A" and a child term named "Category A1" and added it to a new post. This works everywhere, including the post page. (screenshot 4). I've created other weird terms and they all work. However, if the main term is Oceânia and the child-terms are Austrália or Nova Zelândia, then it doesn't.

Any clues?

Thanks.

#615590

https://toolset.com/forums/topic/taxonomy-glitch/page/2/#post-614907

I am not sure, but I am sure that you should not make this changes in the parent theme.
This will be removed as soon you update it.
The correct way would be to use the Child theme.

Please download a Fresh version of your theme and add all changes to the child theme, if possible.

This will make your future development easier and safer.

https://toolset.com/forums/topic/taxonomy-glitch/page/2/#post-614908

Yes, it surely has an effect.
That feature seems to alter the native hierarchy of the terms so it will obviously affect them elsewhere too, where that hierarchy is called.
Deactivating the Plugin won't be enough. The settings instead need to be brought to what they where before, first.
As example, a non-parent that was made primary, should most likely be set back to what it was before.
Altering the Taxonomy in this way will produce unexpected results as it alters the native hierarchy.

https://toolset.com/forums/topic/taxonomy-glitch/page/2/#post-614916

I apologize that I did not see that thread, and was not familiar with the feature of this plugin.
We don't produce YOAST, hence I do not work with it daily.

https://toolset.com/forums/topic/taxonomy-glitch/page/2/#post-614976

According to this, we are still on the spot that this Terms are altered by YOAST, correct?
Since it works for all terms, it must be an exception of this very term, which is most likely due to settings saved against those terms, which alter the hierarchy.

Can I ask, if when you alter the terms names by just one character (Oceana instead of Oceania, or Nova Selandia instead of Nova Zelandia)... does it work then?
That would be the ultimate proof that something, in either a theme or plugin, is altering those exact terms.
There are several places this can happen in your install as we saw.

Can you let me know what the result is of above test?
If this works, I suggest to delete the existing terms which do not work, and recreate them after checking that neither the theme or another plugin alters those terms.
Before you delete and recreate them, also make sure to reset all specific setting you might have applied against them, such as "primary" settings of the term by YOAST.

#615603

Hi Beda,

Thanks for the reply.

Yes, I’ve been using a child-theme from the beginning.

That “Primary” and “make primary” apparently has been released by Yoast in 2012. So, it’s nothing new. But I didn’t know about it either.

“According to this, we are still on the spot that this Terms are altered by YOAST, correct?

No, I don’t think Yoast has anything to do with it. I think the “primary” affects the Yoast breadcrumbs, which I don’t have enabled.

As I mentioned, since I’ve inserted that code (from Minesh instructions) into functions.php that works for all the terms except the Oceania and the child terms of this.

I’ve changed Australia to Australip and Oceania to Oceanit and it still doesn’t work. I’ve changed the slugs as well.

I remember that when I first created the taxonomy with types Australia was put inside "Europa" by mistake, but later I had to changed it to the correct location (oceania). The same happened with the "Nova Zelandia". Not sure if this has some effect, but it came to mind.

Thanks.

#615950
Without EUA.png
Correct Hierarchy.png
Post with EUA and Am de Norte.png
Primary Australia, even if child.png
Posts in Oceania > Australia.png

I took this example:
hidden link

According your taxonomy term hierarchy, here 2 posts should show in:
Oceania > Australia

But those posts are tagged also with:
EUA
America du Norte
(see screenshots).

Further, one term is primary (Australia), while being child to Oceania natively.

In any way, the current Archive for oceania, is correctly applying the term's hierarchy.
When I remove the unwanted terms (America, EUA), it is still displayed correctly.
Please see the screenshot attached as well.

The single Posts however, are not.
I do not know where you insert that in single posts, in the Content Template used, it's not present:
hidden link

So this output comes from the Theme, probably?

I checked all other archives like Europa, Asia, Oceania, they are all showing the right hierarchy.

The Single Post Terms, seem not to be inserted in the Content Template in question.

Hence it must be a problem with code in the theme?

#616125

Hi Beda,

At the moment I have this code in the child theme functions.php in order to display the taxonomy link terms in the post pages because these weren't displaying. Not sure if this is it?

 

if ( ! function_exists( 'penci_category' ) ) {
	function penci_category( $separator ) {
		if ( get_theme_mod( 'penci_featured_cat_hide' ) == true ) {
			$excluded_cat = get_theme_mod( 'penci_featured_cat' );
			$first_time = 1;
			foreach ( ( get_the_category() ) as $category ) {
				if ( $category->cat_ID != $excluded_cat ) {
					if ( $first_time == 1 ) {
						echo '<a class="penci-cat-name" href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a>';
						$first_time = 0;
					}
					else {
						echo wp_kses( $separator, penci_allow_html() ) . '<a class="penci-cat-name" href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a>';
					}
				}
			}
			
			penci_get_the_term_list( get_the_ID(), 'viagens' );
		}
		else {
			$first_time = 1;
			foreach ( ( get_the_category() ) as $category ) {
				if ( $first_time == 1 ) {
					echo '<a class="penci-cat-name" href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a>';
					$first_time = 0;
				}
				else {
					echo wp_kses( $separator, penci_allow_html() ) . '<a class="penci-cat-name" href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a>';
				}
			}
			
			penci_get_the_term_list( get_the_ID(), 'viagens' );
		}
	}
}


if ( ! function_exists( 'penci_get_the_term_list' ) ) {
function penci_get_the_term_list( $id, $taxonomy ) {
	$terms = get_the_terms( $id, $taxonomy );

	if ( is_wp_error( $terms ) )
			return $terms;

	if ( empty( $terms ) )
			return false;

	$links = array();

	foreach ( $terms as $term ) {
			$link = get_term_link( $term, $taxonomy );
			if ( is_wp_error( $link ) ) {
					return $link;
			}
			echo '<a class="penci-cat-name" href="' . esc_url( $link ) . '">' . $term->name . '</a>';
	}
}
}

Thanks.

#616289

Well, it is not displayed with Toolset, it does not use Toolset Code either.

It is a Theme problem, that needs to be solved on the theme level.
As I elaborated earlier, our own code has lines in place that actually order the output terms.

Your code does not have such specific code lines in place.
It gets the terms, but never orders them.

Maybe use wp_get_post_terms() instead?
https://codex.wordpress.org/Function_Reference/wp_get_post_terms

There you have order parameter.

However, this is subject to custom code. If you require help with this code, I suggest to contact the Contractors: https://toolset.com/contractors/