Layout assignment weirdness

Hello,

On this blog post https://devhps.site/on-a-chalk-hillside-december-2022/

There is a list of terms from the species taxonomy. I have highlighted two of them

Both are terms from the species taxonomy, yet the second one displays other plants in the same species, whereas the Acer Palmatum uses a default Wordpress archive display.

There is only one layout assigned to Species, so I’m trying to understand why the Acer leads to a default WP layout and not the one I assigned.

Many thanks, Bill.

Hi Bill,

Thanks for reaching out.
It will be very difficult to recognize the exact reason without investigation. I would suggest you please provide login credentials for your site in a secure note to examine it further, including:

– WordPress Site URL & Login URL
– WordPress Admin username/password

To create a secure note, click the key icon underneath any of your posts.

Thanks

Done.

These are posts, and the taxonomy Species is associated with them.

Hey Bill. I think I might need FTP info on the dev site to give you a full diagnosis. I’m thinking you might have a conflict with another slug as sending the post type in the request fixes the issue. In general I think it would be nice to have an “Assignments Debug” action or some way to peer into what’s going on as this same thing came up yesterday for me.

If your looking for a workaround. Using {{dc:url:path}} as a string expression, you can check if the path is on this problem page.

image

Not sure I understand the problem page thing - but I do understand forcing the post type which I didn’t know about. I’ve added the ?post_type=plant for now on the Blog page where the source URLs are. I’ll add a secure note with FTP access. Thanks Charlie, Bill.

Hi @charlie - any luck via FTP? Both me and Joao have tried and failed to figure this out. Best wishes Bill.

For the /problempage part, that was just an example. For this site to use this kinda of workaround you would use /species/acer-palmatum/ as the value.

This page believes it is “publication” post type for some reason. See the secure note.

Interesting. Here’s what I’ve done:

  1. Disabled all plugins and tested
  2. Re-enabled plugins step by step
  3. End result - no difference, it’s not a plugin
  4. Tried publishing that blog post above - the problem occurs
  5. Un-published that post, problem goes away
  6. Got some code to log which template is being chosen, here’s the result

The file path is to a legacy template inside Pro called template-blank-4.php

  1. I un-published that blog post and ran the test again, here’s the template assignment

Now it points to a single.php template inside Pro.

I’ve left the blog post at Draft and made a fresh Publication post and published that. The Species URLs are working, as far as I can tell.

I now tested the Genus - I cloned the layout and assigned it to the Genus taxonomy. Mixed bag.

https://devhps.site/genus/philadelphus/ - doesn’t work
https://devhps.site/genus/leucanthemum/ - does work

So the Species seems to be working, but Genus not.

Could you do your same test on the Genus links above and see if there’s some other CPT post which is the cause?

Best wishes, Bill.

Hey Bill,

That one in particular is matching to the post type Extended Data. I think that post type can be private if was reading in the site correctly. I also think if you changed the slug on that one it might not overwrite other post type. I imagine this is some timing issue between TaxoPress and ACF Custom Post Types. I will have more info in the secure note for you.

Have a great weekend!

@charlie I’ve figured it out.

I’ve used species, genus and family to associate multiple post types such as plant, post and publication. When you pass the slug to wordpress it’s picking the first item in the term for the post type which leads to the random behaviour.

I asked ChatGPT how that logic worked and it suggested some code, which I enhanced to this result:

function my_custom_get_posts( $query ) {
    if ( $query->is_main_query() && ( is_tax('species') || is_tax('genus') || is_tax('family') ) ) {
        $query->set( 'post_type', 'plant' );
    }
}
add_action( 'pre_get_posts', 'my_custom_get_posts' );

This forces the post type to plant for each term in those taxonomies which means Pro then assigns the right layout.

HOORAY! A learning experience for both of us I think. It’s not Taxopress in this case.

1 Like

Hello Biil,

Awesome Bill. It is good to know that you have managed to get that code and have a resolution to your layout issue.

Cheers.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.